Symfony 仅在远程服务器上显示 "symfony has been installed"
Symfony only showing "symfony has been installed" on remote server
所以,学校给了我这个域,其中包含很多程序的可能性,包括 symfony,我决定尝试建立我的网站,在那里用 symfony 制作,但我无法让路由工作,因为它只显示一条消息说 symfony 已经安装成功,我自己 运行 没有选择,我没有尝试很多,因为我不太了解它,因此这里的问题.
TL:DR
Symfony 仅在远程服务器(由 Neostrada 托管)上显示 "installed successfully" 我希望这里有人可以帮助我。
编辑:这是消息的屏幕截图:
首先,我将 post 这个 link here...
先阅读答案末尾的注释
现在。我不知道你是否知道 MVC 是什么,但简而言之,它是一个名为 Model-View-Controller 的结构,用户首先接触 Controller,在 symfony 中也称为 Action,它选择一个合适的动作函数,geatheres Models(通过与数据库和所有魔法通信),然后将整个包发送到视图(在 Twig 模板框架中创建的 symfony 中)。
文件结构如下:
app //contains main server files
- cache //contains production and dev files, you won't pay much attention to this.
- config //This is where you find the routing.yml, paremeters.yml and other config files
- logs //git logs and other goodies
- Resources //This is where your views are found
bin //Doctrine and goodies, don't pay much attention here for now...
src //This is where the bundles (controllers) are found
- AppBundle //You should get this bundle by default
- Controller //This is where you put your controllers - they have to have a Controller.php sufix (UserController.php)
- Models, Enteties and other folders you want to put in //All custom folders
- YourCustomBundle (note that both are ending with Bundle)
web //This is where you put your css, js etc. files (in js/, css/... subfolders)
现在,如果您转到 src/AppBundle/Controller
中的 HomeController
。在那里你会看到 indexAction
函数。这个触发主索引页面。
注意名称空间、用途以及控制器 class 正在扩展的内容。如果您创建另一个名为 myCustomAction(Request $request)
的操作,您将创建一个准备接受订单的操作。但从哪里来?转到 app/config/routing.yml
,您可能会看到类似这样的内容:
app:
resource: "@AppBundle/Controller/"
type: annotation
在其上方添加:
page:
path: "/"
defaults: { _controller: AppBundle:Home:myCustom }
//note that I first called the bundle (AppBundle, then the HomeController (without the
//Controller part), then the action (no Action part neither)
现在您已经为自己找到了行动之路!现在只需 return 控制器中的一个视图(查看 indexAction),应该是这样的:
$this->render('home/mycustom.html.twig');
在 myCustomAction 函数中。之后在 app/Resources/views/home/
文件夹中创建一个 mycustom.html.twig
文件,这就是您的视图。请注意,Twig 的语法与 PHP.
略有不同
注意:我强烈建议你去symfony官方网站学习。这就是全部TL/DR(太长,没看懂)的文风。那里对 为什么 你正在做某事的细节进行了更好的解释。由于我解释这个概念的速度,我写的内容可能对你有用,也可能不适合你!另外,如果你不熟悉 MVC,我建议你先了解它背后的逻辑,然后再进入 Symfony。
所以,学校给了我这个域,其中包含很多程序的可能性,包括 symfony,我决定尝试建立我的网站,在那里用 symfony 制作,但我无法让路由工作,因为它只显示一条消息说 symfony 已经安装成功,我自己 运行 没有选择,我没有尝试很多,因为我不太了解它,因此这里的问题.
TL:DR Symfony 仅在远程服务器(由 Neostrada 托管)上显示 "installed successfully" 我希望这里有人可以帮助我。
编辑:这是消息的屏幕截图:
首先,我将 post 这个 link here... 先阅读答案末尾的注释
现在。我不知道你是否知道 MVC 是什么,但简而言之,它是一个名为 Model-View-Controller 的结构,用户首先接触 Controller,在 symfony 中也称为 Action,它选择一个合适的动作函数,geatheres Models(通过与数据库和所有魔法通信),然后将整个包发送到视图(在 Twig 模板框架中创建的 symfony 中)。
文件结构如下:
app //contains main server files
- cache //contains production and dev files, you won't pay much attention to this.
- config //This is where you find the routing.yml, paremeters.yml and other config files
- logs //git logs and other goodies
- Resources //This is where your views are found
bin //Doctrine and goodies, don't pay much attention here for now...
src //This is where the bundles (controllers) are found
- AppBundle //You should get this bundle by default
- Controller //This is where you put your controllers - they have to have a Controller.php sufix (UserController.php)
- Models, Enteties and other folders you want to put in //All custom folders
- YourCustomBundle (note that both are ending with Bundle)
web //This is where you put your css, js etc. files (in js/, css/... subfolders)
现在,如果您转到 src/AppBundle/Controller
中的 HomeController
。在那里你会看到 indexAction
函数。这个触发主索引页面。
注意名称空间、用途以及控制器 class 正在扩展的内容。如果您创建另一个名为 myCustomAction(Request $request)
的操作,您将创建一个准备接受订单的操作。但从哪里来?转到 app/config/routing.yml
,您可能会看到类似这样的内容:
app:
resource: "@AppBundle/Controller/"
type: annotation
在其上方添加:
page:
path: "/"
defaults: { _controller: AppBundle:Home:myCustom }
//note that I first called the bundle (AppBundle, then the HomeController (without the
//Controller part), then the action (no Action part neither)
现在您已经为自己找到了行动之路!现在只需 return 控制器中的一个视图(查看 indexAction),应该是这样的:
$this->render('home/mycustom.html.twig');
在 myCustomAction 函数中。之后在 app/Resources/views/home/
文件夹中创建一个 mycustom.html.twig
文件,这就是您的视图。请注意,Twig 的语法与 PHP.
注意:我强烈建议你去symfony官方网站学习。这就是全部TL/DR(太长,没看懂)的文风。那里对 为什么 你正在做某事的细节进行了更好的解释。由于我解释这个概念的速度,我写的内容可能对你有用,也可能不适合你!另外,如果你不熟悉 MVC,我建议你先了解它背后的逻辑,然后再进入 Symfony。