I was practicing to work with Yii2 based on the tutorial in this link : http://www.yiiframework.com/doc-2.0/guide-start-databases.html
I am using Advanced Application
These are the files that i have created:
frontend/models/Country.php
frontend/controllers/CountryController.php
frontend/views/country/index.php
now when i try to access it using index.php?r=country/index i get 404 not found error.
But if i move the actionIndex of CountryController to SiteCountroller and rename it to actionCountry and also move my view file inside site folder (and of course change the name of index.php to country.php) then i can successfully see the list of countries using the address index.php?r=site/country
Any ideas about the 404 not found error?
Examples in tutorial are for basic application and contains app\ in namespaces declaration. And you are using advanced application so for frontend it should begin with frontend\ (see for example SiteController in advanced application).
I think this is the reason since you said that file content is exactly the same, you didn't change default configuration and checked folders, files and classes for correct names.
Related
I am creating content management system for my project. I have created models and controllers in protected folder for admin-panel. It is working fine in admin panel but for accessing same controllers and models only changing the view for user-panel but I got the error of page not exist. I search that question here but i am satisfied with answer my issue remains the same. Thanks in advance.
double check your route file and see if the link or the page that is missing is added to your route file,
,
your route file depends on what mvc framework you are using,
Use aliases to achieve this, i suppose both the folders are independent applications.
http://www.yiiframework.com/doc-2.0/guide-concept-aliases.html
Create the alias for "admin-panel" in common/config/aliases.php
Yii::setAlias('admin-panel', dirname(dirname(__DIR__)) . '/admin-panel');
and while rendering the page in user-panel give the view path using alias
return $this->render("#admin-panel/views/controllername/file");**
**or whatever your folder structure is
I'm new to web development but i know some php basic stuff. Using ftp, i create directories then create simple php scripts there, simple as echoing a string. Which can be accessed like,
www.sampledomain.com/folder1/subfolder2/hello.php
After some time, my friend introduced me to wordpress which is what they described as CMS. I tried to visit her site www.majaflores.com then i click on some stuff there and i noticed the url changed to http://majaflores.com/project/if-i-let-you-in-please-dont-break-anything/
At first, its pretty normal for me because its just a link where there is a folder named "project" and inside it another folder named "if-i-let-you-in-please-dont-break-anything". But when she showed me the ftp folders directory, i didnt see any folder named "project" under main folder of the domain. How did wordpress manage to do this? and how can i implement this manually?
Just wanted to say that like most server-side code environments, PHP also let you parse URLs "manually" and decide what to do accordingly, be it return a file or generate some content.
You can find more information about how PHP is parsing URLs in here:
http://php.net/manual/en/function.parse-url.php
and some discussion regarding it in here:
URL handling – PHP vs Apache Rewrite
This is they way WordPress stores data. U can further see the setting under Permalink.
Under Permalink, u can have options to render ulr as page id, category names and more. You can also use your own format over there.
Just a note, WordPress stored data in database not as a content on FTP directory.
I have a project where I need to mask the url.
Before: example.com/pogi/ako/
After: example.com/ako/
The application is created using codeigniter. Thoug the one found on the sub-directory have another webservice created with codeigniter as well. I tried doing some configurations I know with .htaccess and httpd.conf, but I was not able to make it run.
In the file "application/config/routes.php" add the line:
$route['ako'] = 'pogi/ako';
This will make is so that any request that comes through to example.com/ako will actually go to example.com/pogi/ako but it won't look like that.
Hope this helps!
You may want to remember how Codeigniter Handles URLs, you mentiond Sub Directory in your Question which also is Codeigniter Based Web Service !
When you are Running first Codeigniter App it will Catch your requested Url and get the related Controller and it's Method to Handle it !
Your Controllers can be nested in Sub Directory too ! also as #Ross Mentioned in his answer, this behavior can be override using Routes !
I am using the codeigniter framework for my website.
Previously my website was working fine. But a few days ago I made some changes in code (I add some files for cron job).
When I made these changes my website is not responding it is continuously connecting to the server.
I am using the stencil with the codeigniter.
When I use the ordinary codeigniter view function:
$this->load->view('view_name');
It was working but as I am using stencil paint:
$this->stencil->paint('view_name'); // its not working.
Website URL: http://blogsetu.com/
I would recommend you to read the documentation again there is something you might have missed we can't say any thing without viewing the full source code
However I think you missed to set a layout
from http://scotch.io/docs/stencil
Bare Minimum to Get Started Set a Layout in your Controller
You always will need to set a layout. This is required for Stencil.
Layouts are located in "/views/layouts/". To learn more, visit the
docs about layouts.
$this->stencil->layout('default_layout'); Set and Load a View with
the "paint()" function
To set and load a view you will initiate the "paint()" function. This
function is the equivalent to "$this->load->view($view)" in
Codeigniter.
To learn how to bind data to the view, please click here.
These are located in the "Pages" folder inside of the views folder.
The HTML from these pages are made available in the layout as the
$content variable.
$this->stencil->paint('example_view');
I downloaded the latest version of cakephp. I use cake command line tool for creating a sample project. However, I edited the view file with corresponding controller file but the edited content does not appear. I try a test by rename the view folder of application but the view displayed normally. I think that the view I edited is not the true view cakephp use for rendering.
P/S: the view folder is under the application folder.
-- Edited
The file I edited is: C:\Program Files\xampp\htdocs\cakephp\myapp\views\posts\index.ctp
And the link I was trying to view is http://localhost/cakephp/myapp/posts/index . The edited content does not appear. I also tried an absurd test by deleting the view folder but the webpage display normally. I really don't understand what happened.
You do not need to construct the view again when you delete the var scaffold.
Make a index action (method) in the post controller and then your app get your index view.
Please read the cakephp docs for further information.