Would like to integrate Laravel4's into an existing flat PHP-MySQL site,
while I am applying MCV logic page-by-page I need to keep this site work normally.
Before moving ahead: Q1.Does this intergration work at all ? Q2.Does anyone foresee any problem ?
Sofar I have only done this:
app/routes.php
Route::get('/', function(){
//just keep empty, index.php shows up as intended.
});
public/index.php
test
<?php
//Codes transplanted from Laravel4
//.......start......
/**
* Laravel - A PHP Framework For Web Artisans
*
require __DIR__.'/../bootstrap/autoload.php';
It won't quite work this way. In the middle of MVC we have our "Views" which are what laravel will return to the user for display.
What you can do, though, is put your index.php folder in the app/views directory. If, for example, you put the content of your index.php file in:
app/views/index.blade.php
You can then call it via:
Route::get('/', function(){
return View::make('index');
});
This will have the added benefit of getting you through your first step of moving from a "flat" PHP site and in to the framework.
Note: If you DO try using the implementation you provide in your example, you're going to get a bunch of "Not Found" exceptions.
Related
This may be a dumb question, but I've started exploring Laravel Breeze with vue and I'm not sure how to manage resources and their views. (Using Laravel 9)
For example, if I have a table 'members' and a resource controller 'MemberController', ordinarily in the web.php file I would do something like:
Route::resource('members', MemberController::class)->names('members');
Then I'd create a 'member' folder in my resource/views folder to store the views for that table. I could then call the view from the MemberController something like:
public function index()
{
$members = Member::all();
return view('member.index', compact('members'));
}
I'm trying to do something similar using vue in breeze, so I guess I'd have the vue pages in the 'resources/js/Pages' folder. But this didn't seem to work properly.
I don't know how to transition from the previous approach of handling resources and views to Breeze using vue.
What's the recommended way to handle resources in an SPA with Breeze/vue?
After following Djave's suggestion, I took a look at the sample app from inertia.js and that answered everything.
The problem I had was due to using the dot notation when specifying the path to the vue page. So, in my example above, it should instead be like this:
return view('Member/Index', compact('members'));
The inertia sample app code has a lot of good examples!
I would like to add a new phtml file to my index folder in which I already have several views:
index
landing
And so on... I access them by using the following logic:
sitename.com/index/landing
or
sitename.com/index/index
How can I add the phtml file (my new view) to my index folder so that I'm able to see it when I enter in the browser:
sitename.com/index/mynewview
I'm quite new to the whole Zend Framework, and I'm not sure how the structure works exactly, so I'd like to find out more. Can you guys help me out with this, how am I supposed to do this?
Thanks heaps! :)
P.S. The views are in the following directory structure:
module/application/view/application/index/
and then here are all of the views, this is where I'd like to add my new view and access it from browser like this:
/index/testview
Edit:
When I add the testview.phtml to the index directory and put some test tags like this in it:
<h1> Testing new view page </h1>
It's not being rendered on the browser
Because this is an MVC framework, you're skipping a few steps. You're probably going to get a few harsh responses, but I'll try to fill in the holes for you very quickly.
Ignore the file folder structure for a minute.
This is a route:
/index/landing
Routes point to Actions inside of Controllers to work.
Assuming you have started with the skeleton, open up your module's module.config.php, you should see route config, e.g.:
https://github.com/zendframework/ZendSkeletonApplication/blob/master/module/Application/config/module.config.php#L29
You'll need to add a config entry for the routes you want to serve. It could be as simple as a Literal entry for /index/landing, or something more complex (Segments, Regex, etc.) that handle patterns for routing. Spend some time tinkering and learning here; routes are pretty critical to working with MVC.
When configuring the route, the assumption is that you have a Controller set up, and that this Controller has an Action (to which your route is pointed). That Action, is where you can connect template files (phtml,twig,etc.) to routes:
// dummy action that serves index/testview
public function fooAction(){
$vm = new Zend\View\Model\ViewModel();
$vm->setTemplate('index/testview');
return $vm;
}
That index/testview, will be in your module's view templates, not in your public folder.
I think that's a reasonable primer to get you on your way!
Take some time to learn:
http://zf2.readthedocs.io/en/latest/index.html#userguide
Maybe start here:
http://zf2.readthedocs.io/en/latest/in-depth-guide/understanding-routing.html
ZF2 (V3 is coming!) is a beautiful thing, it's worth it.
Good luck.
I have a PHP Slim and Backbone.JS setup and all my code is now working without any problems.
The only issue I have is that the code I have is minified into one file with Grunt.JS and is loaded at the bottom of each page.
So my Backbone render call is fired on all my pages within my site and not just the path I want it to run on.
I have now tried to use Backbones Router to fire the render on the path I want it to run on, I did not think this would work and it did not as I am using PHP slim as the routing agent and of course Backbone needs a /#/ route path.
Now when I had this Backbone route set up I did try to get PHP Slim to redirect the /#/ route to the clean PHP Slim route path. PHP Slim did not like this at all, when I use the following code,
$app->get('/#/MYPATHHERE', function () use ($app) {
$app->redirect('/REALLPATHTOGOTO');
});
it gave me a PHP Slim error, it looks like PHP Slim does not like the /#/ route.
So what is the best method for doing this?
I am thinking that I could just call the render function within the PHP page that I am getting PHP Slim to render on my selected route? or is there a better method for doing this?
Thanks
Glenn.
Ok got this to work with Backbone, did some more research and enabling pushState to true on the Backbone.history.start then it works without the need for the hash routing.
I want to learn Laravel, so I just created my first project in my Sites folder. The folder in which it is in is now Sites/dump/laravel_test/. So following the quickstart docs I made a route in app/routes.php as follows:
Route::get('users', function() {
return 'Users!';
});
After saving the file I tried
http://localhost/~kramer65/dump/laravel_test/users
http://localhost/~kramer65/dump/laravel_test/public/users
but unfortunately, I get a 404 for both urls.
Since it's such a simple start, I don't really know what I should be checking. Could anybody give me some tips on what I could be doing wrong here?
[EDIT]
Turns out I had to give some permissions to app/storage/meta/services.json
I still wonder though, what are the most suitable and safe permissions to use here?
I have a website with many scripts written in "pure" PHP, i.e. no specific framework has been used to write the files. Furthermore, all the URLs are custom using .htaccess and specific PHP scripts.
For a smooth transition, I would like to start using CodeIgniter for new pages without disrupting access to the old pages, but all the documentation I've seen on CodeIgniter gives the impression that the whole website (perhaps with a few exceptions) needs to be based on the framework.
Would it be possible to use the framework for single pages here and there while leaving old URLs and code intact?
Short answer, yes.
You could access the CI framework from a subfolder, for instance, leaving the existing site untouched.
i.e
www.site.com/my_new_app/controller/method/
where my_new_app is the renamed application folder.
I'm going to go on the assumption that you already have a basic template system in place, and are able to render full pages with your existing site. Since Codeigniter is really just a framework, there's nothing to stop you from using vanilla php, like include, or additional libraries and classes. So, one thing you can do is dump your site into a sub directory in your views folder, then create a "master" controller which does nothing but load full html pages.
class Master extends CI_Controller {
function __construct()
{
parent::__construct();
}
function index()
{
// We're expecting something like "registration/how-to-apply" here
// Whatever your URL is. The .php extension is optional
$args = func_get_args();
$path = 'path_to_my_old_site/'.explode('/', $args);
$this->load->view($path);
}
}
// Then use this in config/routes.php
$route['(:any)'] = 'master/index/$1';
This will route all pages through the master controller. So, yoursite.com/pages/faq will load the file application/views/old_site/pages/faq.php. You can apply different routes as you see fit.
This way, you can take your time migrating to use Codeigniter conventions, one page at a time.