I am new to yii framework. On yii version:2.0.1 I have created a module in which I tried to generate a CRUD model using the gii functionality. After putting the model class, controller class and view path when I clicked on generate gii showed all the files has been created successfully. But when I tried to view, below message has been shown to me,
The view file does not exist :
C:\xampp\htdocs\advanced\backend\modules\settings\views\companies\index.php
I found the view files in web directory not in the path I entered. Hence the error.
Here is my inputs to gii,
Model Class:
backend\modules\settings\models\Companies
Search Model Class:
backend\modules\settings\models\CompaniesSearch
Controller Class:
backend\modules\settings\controllers\CompaniesController
View Path:
backend\modules\settings\views\companies
When I click generate I have given below message :
Generating code using template "C:\xampp\htdocs\advanced\vendor\yiisoft\yii2-gii\generators\crud/default"...
generated modules\settings\controllers\CompaniesController.php
generated modules\settings\models\CompaniesSearch.php
generated backend\modules\settings\views\companies\_form.php
generated backend\modules\settings\views\companies\_search.php
generated backend\modules\settings\views\companies\create.php
generated backend\modules\settings\views\companies\index.php
generated backend\modules\settings\views\companies\update.php
generated backend\modules\settings\views\companies\view.php
done!
Does anybody have any idea why is it happening.
Thanks in advance.
I solved similar problem by changing
backend\modules\settings\views\companies
into
#backend/modules/settings/views/companies
Hopefully it helps someone in future
You missed one final folder and alias in View Path. It should be #backend\modules\settings\views\companies.
As you can see in creation log, the generated files are in wrong place (root views folder), that's why the error is thrown.
Have the same problem. Solved entering #backend/modules/settings/views/companies instead backend\modules\settings\views\companies.
See on slashes.
For view path in CRUD generator, enter the absolute or full path. For example
/home/developer/workspace/advanced/backend/views/<your view folder>
put this in the VIEW PATH
#backend/modules/settings/views/companies
and it's done!
I have tried with absolute path i,e
C:/xampp/htdocs/advanced/backend/modules/settings/views/companies
It worked for the absolute path.
I tried this is working by entering:
/Applications/XAMPP/htdocs/advanced/backend/modules/settings/views/companies
I hope you can do it well.
I'm using the advanced theme
Here is my Gii setup in case it is helpful for anyone
module generator
----------------
module class: backend\modules\posts\Module
module id: posts
model generator
---------------
table name: posts
model class: Posts
namespace: backend\modules\posts\models
Enable I18n: checked. category: app
CRUD generator
--------------
Model class: backend\modules\posts\models\Posts
Search model class: backend\modules\posts\models\PostsSearch
Controller class: backend\modules\posts\controllers\PostsController
View path: #backend/modules/posts/views/posts
Enable I18n: checked. category: app
Enable pjax: checked
If you are using some non-default user management (like amnah module),
you need to change Users::className() in the models\Posts.php to
\amnah\yii2\user\models\User::className()
Previously I put a model into the incorrect directory when wanting to achieve an absolute path (address it absolutely as it seems to be more often functional) -
app/backend/modules/settings .
Notice the 'app' in the beginning (the /app is the main directory in Yii starter kit) which I thought would avoid the relative path but must NOT be there nor #mail sign, but on the contrary, it did the opposite - it appended it relatively with its absolute length to the /document root directory, basically duplicated it,
"app/myproject.com/app/backend/modules/settings"
So it unwinds from the model location, the causes of Gii complaints about incorrect paths or put also controllers the incorrect way.
Also strangely enough for views in contrast to models, it had to be put the upper mentioned different way with the # relative reference sign annotation (which was not allowed to be used for controllers or models at the time of writing)
#backend/modules/settings/views/companies, otherwise it appended the directory tree into the document root, again concatenated - the web directory of backend backend/web (backend/modules/settings/views/companies)
Related
Im new to typo3 and ive been trying to develop an extension for it. When I load the plugin to the page i get and error:
Sorry, the requested view was not found.
The technical reason is: No template was found. View could not be resolved for action "search" in class "LoginController".
In the login controller i have a function searchAction and I do have a template inside
\Resources\Private\Templates\StoreInventory\Search.html
What might be the error? I followed the documentation for extension development by typo3. I even downloaded the code from GIT and tried using that but no luck.
TL;DR: It should be placed at Resources/Private/Templates/Login/Search.html
explanation:
From your question I can tell you've used the documentation on https://docs.typo3.org/m/typo3/book-extbasefluid/master/en-us/4-FirstExtension/6-adding-the-template.html
It is not wrong, but you've missed a vital step. When you take a look at the path they are using you'll see that a lot is done automagically. Let's break it down.
They have a controller with an action and a template related to it in the following path
controller:
\MyVendor\StoreInventory\Controller\StoreInventoryController
action: listAction
template: EXT:store_inventory/Resources/Private/Templates/StoreInventory/List.html
If you look closely you'll see that the template path is made up from several components.
the extension (EXT:store_inventory)
the default template directory path (Resources/Private/Templates)
The Controller name without the controller suffix (StoreInventory)
the Action name without the action suffix (List)
the .html suffix
If you take that information and apply it to your case it would be:
the extension (EXT:your_extension_name)
the default template directory path (Resources/Private/Templates)
The Controller name without the controller suffix (Login)
the Action name without the action suffix (Search)
the .html suffix
So the end result would be something like
EXT:your_extension_name/Resources/Private/Templates/Login/Search.html
It is true that you can use typoscript to change this behaviour or set overrides or extended templating for instance. But I think you're working from the default, and this should be the working path for you now
First check your templateRootPaths in Configuration/TypoScript/setup.typoscript
And set accordingly.
Try placing the file at \Resources\Private\Templates\Search.html as \Resources\Private\Templates is the default path unless you have altered it.
Laravel 5.7.
If I navigate to a page that does not exist, I get 404 error page handling.
That view is located in vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Views/404.blade.php
However this file extends:
#extends('errors::illustrated-layout')
This is located in the same folder, and is named illustrated-layout.blade.php
So I guess that the errors:: part points to the specific folder., e.g. vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Views/
Question: Is this type of pointer something that could be created manually, so a person wouldn't have to write the entire path to a specific folder, when extending a view? Would make things much more clean.
You can add a view namespace and achieve the same result.
For example, you can add the following in AppServiceProvider#boot:
$this->app['view']->addNamespace('admin', base_path() . '/resources/views/admin');
and let's suppose you have a blade file in resources/views/admin/layouts/master.blade.php
you can access it with admin::layouts.master
I am a Drupal dev and new to code-igniter or any such php frameworks.
Now i have to modify an existing application done on codeigniter and the structure must be as follows:
example.com/motors
example.com/motors/car-for-sale
example.com/motors/car-for-rent etc.
Before it has only one url example.com/motors and i want to create more urls as mentioned above.
In the application\views\content folder i have the following structure:
application\views\content\motors.php
application\views\content\motors
application\views\content\motors\car-for-sale.php
In the application\controller folder i have the following structure:
application\controller\motors.php
application\controller\motors\motors.php
application\controller\motors\car-for-sale.php
I want to get the url example.com/motors & example.com/motors/car-for-sale from the files resides in the motors folder.Also how can i set a default file to load when i open example.com/motors?
You can't have a (controllers) directory that matches the name of a controller class at the same level. That is, since you have a controllers/motors.php, the files under controllers/motors/* will never be reached.
Instead (and this is the answer to your second question), you should set the default_controller name and rename controllers/motors.php to controllers/motors/<default_controller>.php.
Note that the default_controller setting points to a controller name (not a file location) and is applied to all directories. That is, if you set it to 'Default', then controllers/Default.php will be used when you open http://domain.tld/ and controllers/motors/Default.php will be used if you open http://domain.tld/motors/.
Also, your controller names MUST start with a capital letter, so default.php would be incorrect and should be Default.php instead. This might be working for you on Windows right now (because of its case-insensitive file system), but as soon as you upload your site to a Linux (or other UNIX-based) host, any classes with file names that don't start with a capital letter won't work.
It looks like you're trying to build a CodeIgniter site with a completely different paradigm from what it is designed around.
The structure you are after can be set up using the routes.php file within application/config
In there, you can set routes to go to any location needed, so for you, something like:
$routes['motors/cars-for-sale'] => 'motors/cars_for_sale';
$routes['motors/cars-for-rent'] => 'motors/cars_for_rent';
Then in application/controller you'd have a Motors.php file, which starts:
class Motors extends CI_Controller{
And also has the functions cars_for_sale and cars_for_rent
The mappings in routes sets this to link together.
In order to get the views you want for any given route, in the controller function, you'd have:
$this->load->view('path/to/view/file', $array_of_data); // view path does not need the .php extension
I'd recommend having a look and possibly even a follow through of the CodeIgniter tutorial in their documentation
In my Laravel 4 application's root directory, I have a folder themes. Inside the themes folder, I have default and azure.
How can I access view from this themes/default folder in a specific route.
Route::get('{slug}', function($slug) {
// make view from themes/default here
});
My directory structure:
-app
--themes
---default
---azure
I need to load views from localhost/laravel/app/themes/default folder. Please explain this.
This is entirely possible with Laravel 4. What you're after is actually the view environment.
You can register namespace hints or just extra locations that the finder will cascade too. Take a look here
You'd add a location like so:
View::addLocation('/path/to/your/views');
It might be easier if you namespace them though, just in case you have conflicting file names as your path is appended to the array so it will only cascade so far until it finds an appropriate match. Namespaced views are loaded with the double colon syntax.
View::addNamespace('theme', '/path/to/themes/views');
return View::make('theme::view.name');
You can also give addNamespace an array of view paths instead of a single path.
Here I am not accessing my project from public folder. Instead of this I am accessing from project root itself.
I have seen a forum discussion about Using alternative path for views here. But I am little confused about this.The discussed solution was,
You'd add a location like,
View::addLocation('/path/to/your/views');
Then add namespace for theme,
View::addNamespace('theme', '/path/to/themes/views');
Then render it,
return View::make('theme::view.name');
What will be the value for /path/to/ ?
Can I use the same project in different operating system without changing the path?
Yes, we can do this using the following,
Put the following in app/start/global.php
View::addLocation(app('path').'/themes/default');
View::addNamespace('theme', app('path').'/themes/default');
Then call view like the default way,
return View::make('page');
This will render page.php or page.blade.php file from project_directory/app/themes/defualt folder.
I've developed a theme package for laravel 5 with features like:
Views & Asset seperation in theme folders
Theme inheritence: Extend any theme and create Theme hierarcies
Try it here: igaster/laravel-theme
\View::addLocation($directory); works fine but the new right way to do it is using loadViewsFrom($path, $namespace) (available on any service provider).
Being new to Cake on PHP, I am trying to work out if I have a URL, what would be the easiest way to find the controller code for it?
The URL on my local machine is something like:
http://foofoofoo.local/protected/admin/org/edit/1
I have worked out that the location of the view for this file is at this location on my machine:
/var/www/MyApp/protected/app/views/org/admin_edit.ctp
I thought what I'd do is do a search throughout the entire codebase for anything referencing admin_edit.ctp. I found two entries, and changed them to see if I had found the point where the view is called, but despite changing the file name on these entries - the app still works when I visit the URL: http://foofoofoo.local/protected/admin/org/edit/1
I just want to see where the admin_edit.ctp file is being called within the site.
URL: http://foofoofoo.local/protected/admin/org/edit/1
This means I can assume you have a added a route in your /app/Config/routes.php. Where this is pointing can not be said since we don't have access to this file.
Why can I assume you have added this to your routes? Because the posted URL is not matching the CakePHP Conventions which clearly states that controllers should be defined in plural. Since the URL will be accessing the Controller directly through the Controller, unless a route has been specified, I know that the OrgController does not exist. Why?
Try Inflector::pluralize('Org'). It will return 'Orgs' to you. And thus meaning the controller should be called OrgsController and you should be accessing this Controller via the following URL.
http://foofoofoo.local/protected/admin/orgs/edit/1
In this OrgsController there should be an action (function) called admin_edit(), because you have prepended the org with Admin, which is a prefix.
It can be possible that the /protected part, is part of the URL as well, but do not know where your main /App is located and what part of the URL is pointing to the /app/webroot/index.php file.
The Views can be found at /app/View/Orgs/*.ctp.
If you are still having trouble finding your files. Please start with the Blog tutorial written by the Cake Community. This tutorial describes all the neat built-in tricks and will get your first app running in no-time. Please read that first!
If you are still having trouble, feel free to update your question and add the /app/Config/routes.php file.
Under Cake 1.3, if your application has an AppController (check if the file app/app_controller.php exists), you can put this code in the beforeFilter method:
debug($this->params);
It will print an array on your app pages when you are in debug mode, with the name of the controller and the action used.
Array
(
...
[controller] => controller_name
[action] => action_name
...
)
If the AppController does not contain any beforeFilter method, you can just create it:
function beforeFilter()
{
debug($this->params);
}