Laravel 3: View doesn't exist - laravel

I've just inherited a Laravel 3 site which works on a custom CMS. The CMS output is rendered through a theme folder at the / level so my folder structure looks like:
-application
-bundles
-laravel
-public
-storage
-theme
-errors
-layouts
-partials
I've made a search controller within '/application/controllers' and I want to create my view for the output in the '/theme/layouts' folder with the other template files. When I've worked with Laravel before, my views are all within '/application/views' and I can specify my view with:
public $layout = 'layouts.default';
..which would use '/application/views/layouts/default.blade.php'
How can I get my controller to render the view using my '/theme/layouts/searchTemplate.php' file and pass in the search data from the controller?

If you really need to put these files in a separate folder you should probably use bundles (see docs).
However, a quick and dirty solution is to add a hook in the view loader event (application/start.php):
Event::listen(View::loader, function($bundle, $view)
{
if($bundle == 'theme') {
return View::file('application', $view, Bundle::path('application').'theme');
}
return View::file($bundle, $view, Bundle::path($bundle).'views');
});
You can then make views like:
View::make('theme::layouts.default');
which will load the file "application/theme/layouts/default.blade.php".

In your application folder, there is a folder called 'views'
You have to create the default.php in applications/views/layouts/
With 'layouts.defaults' it search in the views folder to a folder that will be called layouts.
So the complete folder for 'layouts.default' would be: ./application/views/layouts/default.php
Edit: answer is not relative anymore

Related

how to move some controllers and views to subfolder?

I have old project that I want to move it is controllers and views to my new project bu copy and past them, the controller will be pasted in subfolder Http\mod1 and views into Resources\views\mod1, also I will copy the web.php content of the old project and past it into my new project using route grouping for it is routes.
Now since there is a lot of views and controller is there is some way to instruct Laravel that the view that are called by the controllers under group are located under sub folder mod1 ? and how to make the route group point to the controllers inside that group without modifying them one by one?
You can achieve it by doing as below.
Move your View file in mod1 subfolder
// In your Controller
namespace App\Http\Controllers\mod1;
...
return view('mod1/index'); // to return your view inside a method for example.
// In Your route for example you can goup all your controllers in namespace
Route::group([ 'namespace' => 'mod1'] ,function() {
Route::GET('/user', 'UserController#getuser');
...
});

File extension for Laravel Blade as an 'index' page

My 'homepage' for a Laravel install works great, which is: welcome.blade.php however, my question is - how do I get other basic 'static' pages to work correctly.
My preferred site top level navigation has for example, 'about us', so what I'd like to do is create a directory called 'about us' and then place a similar page as blade.index.php in there but it throws an error.
So, my question is - how do I name the file within a directory within the web application.
Thanks
You've got it flipped. blade always goes in the middle.
index.blade.php
return view('index');
/about/index.blade.php
return view('about.index');
You will need put your view file inside static folder of your choice and make sure your filename should contain blade in the middle for ex: "about.blade.php" and after that you will need to return that file with folder_name/file_name.
return view('Folder_name/File_name');
Try above code you are good to go.

How to create a New Page on Prestashop 1.7 Child Theme

I want to create a new page on my prestashop. I dont want to use the CMS to create the page, I need essentially a totally new page.
I have tried duplicating current .tpl's and renaming them - but I can never navigate to them - what is the url to access the new template?
E.g. say my site is www.xyz.com the "my account" template, sits under template/customer/my-account.tpl this my account page is normally accessed at xyz.com/my-account
I want a new but similar page - so I duplicate this template, rename it to my-account-new and change something in it, why can you not access the new template by change the URL to end with my-account-new - I just get a 404.
What am I missing?
Thanks
:)
you can add a new front controller in a custom module :
ModuleName/controllers/front/ControllerName.php
Then your new controller is a class that should be defined like :
Module::getInstanceByName('<ModuleName>');
class <ModuleName><ControllerName>ModuleFrontController extends ModuleFrontController
Then you add the method
public function initContent(){
parent::initContent();
$this->setTemplate('<templateFolder>/<templateName>');
}
You can now navigate to the template by going to index.php?fc=module&module=ModuleName&controller=ControllerName
So in this example replace every ModuleName with the name of your custom module and ControllerName with the name of your controller (for example MyCustomModule and MyCustomController).
The template will be in the your theme folder for example you can add customAddress in themes/ThemeName/templates/customer/customAddress.tpl
in which case the call to setTemplate would become :
$this->setTemplate('customer/customAddress');
I hope this helps.

Loading a laravel view with .html extension

Is it possible to have Laravel load view templates with a .html extension?
I'm rebuilding an existing app that has a bunch of .html files that are uploaded by users. It's a sort of multi-tenant application where each user can control the look and feel of their area by uploading templates.
I need to rebuild the app and make the change completely transparent to the users so I'd like to keep the .html extensions.
The best way I have found is to use View::addExtension in your base controller;
Here's my code sample:
View::addExtension('blade.html','blade');
class BaseController extends Controller {
/**
* Setup the layout used by the controller.
*
* #return void
*/
protected function setupLayout()
{
// Allows us to use easy-to-edit html extension files.
// You can set 2nd param to 'php' is you want to
// just process with php (no blade tags)
View::addExtension('blade.html','blade');
if ( ! is_null($this->layout))
{
$this->layout = View::make($this->layout);
}
}
}
I am afraid Blade engine loads .php and .blade.php files only.
From your description I assume the view files are static, since they are HTML only.
If so, rename them to .php after user uploads view files - should not bring performance impact to your application, since there is nothing to process anyway.

codeigniter:everything created through MVC pattern?

I'm studying codeigniter and I would realize a simple application. I'm asking if every page, even if doesn't not contain directly dynamic element must be create through MVC pattern? I explain myself: my home page will not contain anything of dinamic. only an header, menu and footer. it needs to create model,controller and view to handle this situation or I create simple the home page?
You always have to create a controller because that is what is called from the url.
As far as the view and model. You don't always have to create either.
I've got plenty of pages with static info so I don't need any model interaction at all.
Without a view you are kind of defeating the purpose of the MVC. It is possible for the controller to just echo all your html for the page but I wouldn't do it.
The way I do it is that I have a default view that contains the header and footer. A content view that all my content for the page goes into. I then pump my view for the page into the content view then that into the default view to create my page.
$arrData["vwsContent"] = $this->load->view("your view for the page", $arrData, TRUE);
$arrData["vwsPageContent"] = $this->load->view("content template view", $arrData, TRUE);
$this->load->view("default template view", $arrData, FALSE);
In this way I can have different content views but the same default view for all the pages. For instance my homepage looks different than my regular pages so I would have a HOME template to use instead of a CONTENT template.
You can define the home page function in any controller.
In routes.php the default controller and action can be defined
$route['default_controller'] = "welcome"; (welcome can be replaced by any your prefer controller) .
Create function with name index
function index(){
$this->load->view('index');
}
Then create the file index.php in "views" folder.
In index.php you can put all your HTML static content. You can use URL helper [ function base_url()] for images/css/js path.

Resources