I want to change views folder of yii2 to structure bellow
views
----default
----site
----index.php
----error.php
----login.php
In the siteController i'm using code bellow
public function actionIndex(){
return $this->render('default/index');
}
and error
The view file does not exist: D:\wamp\www\yii2\backend\views\site\default/index.php
Please help me
With your current code, the Site Controller search the view file under his view's folder /views/site, you need to get the right path:
$this->render('../default/site/index');
I suggest to create an alias for be more flexible, like #default_views in your main-local file:
'aliases' => [
'#default_views' => '../default/',
So, the function:
public function actionIndex(){
return $this->render(Yii::getAlias('#default_views') . 'site/index');
}
Related
Im new to the codeigniter and cant understand why view is not loaded from the subfolders
i write simple controller and view file
Controller location application\controllers\Test.php
<?php
class Test extends CI_Controller{
public function index()
{
$data = array(
'name' => 'ivan'
);
$this->load->view('test/new', $this->data);
}
}
View location application\views\test\new.php
<div class="container">
<h1>Test</h1>
</div>
When i try to access url http://localhost/test/new im getting error
404 Page Not Found
The page you requested was not found.
Because you are in index function so just create another function named new if you want to run localhost/test/new
please run this url "http://localhost/test/", because your controller file index method are using.
I have created a module in Laravel and im using views on that module, my structure is this:
Modules
-> MyModule
->->Controllers
->->Views
->->->MyModule.blade.php
But i have the headers and footer done on resources->views->layouts->base.blade.php
So how can i call this one so i can use the same base layout in all modules? it is possible on Laravel 5?
Already tried this
#include('layouts.base')
but im getting
Trying to get property of non-object (View: ... resources\views\layouts\base.blade.php
Thank you.
The structure of blade is relative to the views folder in the the resources folder.
Thus making your #include() have a structure like the this:
#include('DIRECTORY.BLADE')
and you can include your various blade contents by using #yield()
#yield('YIELD_FIELD_NAME')
If you are trying to have blades extent from that layout you would call that at the top of the blade files you want to extend off it.
#extends('DIRECTORY.BLADE')
This is an example blade file that can extend your layout if your layout contains the #yield('content') tag in it.
example.blade.php
#extends('layouts.base')
#section('content')
YOUR BLADES HTML/CONTENT
#endsection
https://laravel.com/docs/5.4/blade#defining-a-layout
How to add Auth middleware to controller:
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('auth');
}
Here is an example Controller:
https://github.com/jeremykenedy/laravel-auth/blob/master/app/Http/Controllers/UsersManagementController.php
Here is an example of a view that uses that controller:
https://github.com/jeremykenedy/laravel-auth/blob/master/resources/views/usersmanagement/show-user.blade.php
Here is an example of the template that view uses:
https://github.com/jeremykenedy/laravel-auth/blob/master/resources/views/layouts/app.blade.php
Here is the routing file for the above examples:
https://github.com/jeremykenedy/laravel-auth/blob/master/routes/web.php
Ok i was abble to get the Auth work on Module structure, just need to add this on your routes.php
Route::group(['middleware' => ['web']], function () {
//Your routes
});
Created controller and tried to access it by url got an error like 404 Error
The page you are looking for could not be found.
Try checking the URL for errors, then hit the refresh button on your browser.
Used the fallowing procedure
//created route
'app-test-index' => array(
'test',
array(
'controller' => 'test',
'action' => 'index',
),
),
//controller
namespace App\Controller;
use Ppb\Controller\Action\AbstractAction,
Cube\Controller\Front,
Cube\View,
Cube\Validate\Url as UrlValidator,
Cube\Controller\Request,
Ppb\Service;
class Test extends AbstractAction
{
public function Index()
{
die('ok');
}
public function test()
{
die('ok');
}
}
How to create model view controller in PHPProbid
how to customize PHPProbid
Thanks
How to create a controller in PHPPROBID version 7.8
Step 1: Create a controller file in corresponding module
step 2: Edit the model Acl file in corresponding module
for example
a) Create a controller Test.php in module/App/src/App/Controller.
b) Add resources (Give permissions to user roles for the created controller) in
module/App/src/App/Model/Acl.php file
In our case you need to add the following lines
$test = new Permissions\Resource('Test');
$this->addResource($test);
$this->allow('Guest', 'Test');
It is important to note that the module/App/src/App/Model/Acl.php file will be replaced during phpprobid update
so you need to create a folder named mods in root(IF already exist no need to create).
Copy the file to mods folder with corresponding folder structure
In our example copy Acl.php to mods/module/App/src/App/Model folder.
Now you can access your controller
http://your_domain.com/index.php?module=app&controller=test&action=index
I am building on an application in which i need to built the API's and then i found this extenison : Link below ->
https://github.com/evan108108/RESTFullYii
But i was wondering that how to override the existing methods present in the controller.
For eg.
I have my actionView method as follows:
public function actionView($id) {
$this->render('view', array(
'model' => $this->loadModel($id),
));
}
And this outputs me the all the fields from the database. But the thing i want is that i should write some logic and the output should be generated according to my logic.
Please help me. I am stuck???
I'm learning Laravel, and for my first project I'd like to create my portfolio. However, the first task I have to do is confusing me.
So I created my templates, layout.blade.php and home.blade.php. That makes sense to me, but now how do I tell Laravel, or how do I route to home.blade.php?
I'm looking for an explanation rather then just code. I'm trying to learn.
Actually, a view in MVC application is just a part of the application and it's only for presentation logic, the UI and one doesn't call/load a view directly without the help of another part (controller/function) of the application. Basically, you make a request to a route and that route passes the control over to a controller/function and from there you show/load the view. So it's not a tutorial site and it's also not possible to explain about MVC here, you should read about it and for Laravel, it's best place to understand the basics on it's documentation, well explained with examples, anyways.
In case of Laravel, you should create a controller/class or an anonymous function in your apps/routes.php file and show the view from one of those. Just follow the given instruction step by step.
Using a Class:
To create a route to your Home Controller you should add this code in your app/routes.php
// This will call "showWelcome" method in your "HomeController" class
Route::any('/', array( 'as' => 'home', 'uses' => 'HomeController#showWelcome' ));
Then create the HomeController controller/class (create a file in your controllers folder and save this file using HomeController.php as it's name) then paste the code given below
class HomeController extends BaseController {
public function showWelcome()
{
// whatever you do, do it here
// prepare some data to use in the view (optional)
$data['page_title'] = 'Home Page';
// finally load the view
return View::make('home', $data);
}
}
If you have {{ $title }} in your home.blade.php then it'll print Home Page. So, to use a view you need a controller or an anonymous function and load the view from the controller/function.
Using an anonymous function:
Also, you can use an anonymous function instead of a controller/class to show the view from directly your route, i.e.
Route::any('/', function(){
// return View::make('home');
// or this
$data['page_title'] = 'Home Page'; // (optional)
return View::make('home', $data);
});
Using this approach, whenever you make a request to the home page, Laravel will call the anonymous function given in/as route's callback and from there you show your view.
Make sure to extend the the master/main layout in sub view (home):
Also, remember that, you have following at the first line of your home.blade.php file
#extends('layouts.layout')
It looks confusing, you may rename the main layout (layout.blade.php) to master.blade.php and use following in your home.blade.php instead
#extends('layouts.master')
Read the doc/understand basics:
You should read Laravel's documentation properly, (check templates to understand blade templating) and also read some MVC examples, that may help you too understand the basics of an MVC framework (you may find more by googling) and some good posts about MVC on SO.
Check it routing in Laravel.
You need to use route file and controllers
Create needed function in your Controller file and create a template file for example
class UserController extends BaseController {
/**
* Show the profile for the given user.
*/
public function showProfile($id)
{
$user = User::find($id);
return View::make('user.profile', array('user' => $user));
}
}
you need to create view file views/user/profile.blade.php
View::make('user.profile', array('user' => $user)) == views/user/profile.blade.php
And you should read it http://laravel.com/docs/responses and also this http://laravel.com/docs/quick#creating-a-view