Comments (35)
Hi gyoza,
When you extend the PageController, you'll notice that the PageController has this vital line (highlighted):
https://github.com/JVMartin/angel/blob/master/src/controllers/PageController.php#L15
$this->data['page'] = $page;
That is where $page is loaded into the $data array. The $data array is then passed to all views, because its elements are referenced everywhere. It also contains all messages (errors, success, etc.). For instance, when showing the title of the page in the front-end page blade you can see that $page is accessed:
https://github.com/JVMartin/angel/blob/master/src/views/page.blade.php#L3
The page that is loaded is from the URL specified from this route variable here:
https://github.com/JVMartin/angel/blob/master/src/routes.php#L208
Note that this route has a variable in its very base, letting us create pages for URLs like /about-us
and /contact
, etc. In order to make a new page with an URL, it has to be in the database if you're going to load it from the PageController in this fashion.
I'm available on Skype (JunkGrave) if you'd like to share your screen, I could walk you through anything you'd like to accomplish!
Hope this helps.
-Jacob
from angel-core.
Also, have you seen this tutorial I made?
https://www.youtube.com/watch?v=6iuZ8p-x5bY
I don't think I've put the link in the docs yet, I'll have to do that.
from angel-core.
So pretty much i have to inject the database with the code of the page?
as for the tutorial you kind of click and bop around in folders without the full path showing and you do this quickly so it is hard for me to keep up hehe.
from angel-core.
Maybe I just need to change my submit button to use your route then?
from angel-core.
You don't necessarily have to put any code in the database. In that video, I'm writing the home.blade.php
with its own HTML code / scaffolding, and only the content is loaded from the DB. I usually just put content in the CMS database, while keeping all the actual HTML code for the structure of the pages in the blade files like this. If you look at the left hand side of the screen, you can see the full directory structure for my workflow layed out in the IDE that I have open. All I'm saying above is that if you want to use the $page
variable (which is used by default from the page.blade.php
we extend for many pages), it is a model loaded into the views from the PageController@show
method. In that case, the page needs to have the same URI as the route being requested and as the method being called. (The video goes through this carefully.)
As for your form, you can have it post to any route and controller you'd like and process it however you'd like! Angel doesn't modify Laravel in any way, it's just a set of controllers and models to add some basic CMS functionality.
from angel-core.
Well I have a page called page2 created in angel and my route takes my sanitized form data and send its through my route for my button and then pushes it to /page2 and i get the missing page error.
from angel-core.
home.blade.php
{{ Form::open(array('method' => 'PUT', 'action' => 'PageController@returnmail')) }}
plus other junk and a submit button.
{{ Form::submit('Save') }}
{{ Form::reset('Reset') }}
{{ Form::close() }}
routes.php
Route::put('/returnmail', 'PageController@returnmail', array('title'=>'returnmail', 'page'=>'returnmail'));
Route::post('/returnmail', 'PageController@returnmail', array('title'=>'returnmail', 'page'=>'returnmail'));
Route::post('form-submit', array('title'=>'returnmail', 'page'=>'returnmail','before'=>'csrf',function(){
// form validation here.
}
get this error when i post the form.
ErrorException
Undefined variable: page (View: /var/www/project/app/views/pages/returnmail.blade.php)
open: /var/www/project/app/storage/views/626caa1645f58d41bbd44f02136330c6
<?php $__env->startSection('title', $page->title); ?>
<?php $__env->startSection('meta'); ?>
<?php echo $page->meta_html(); ?>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('css'); ?>
<?php if ($page->css): ?>
<style>
i think thats everything..
from angel-core.
The PageController
is for displaying pages. You should not be posting form data to it in my opinion. It's also not considered good practice to be doing validation from a Route::
function closure like that.
All you need to do to create a form in Laravel is...
View:
{{ Form::open(array('route'=>'contact_form')) }}
{{ Form::hidden('test', 'test') }}
{{ Form::submit('Send') }}
{{ Form::close() }}
Route:
Route::post('contact-form', array(
'as' => 'contact_form',
'before' => 'csrf'
'uses' => 'ContactController@submission'
));
Controller:
class ContactController extends BaseController {
public function submission()
{
echo 'Received data: ' . Input::get('test');
}
}
from angel-core.
Well, i am not trying to make a contact page, I am trying to just post data from one page to pull it from the next page nothing fancy, nothing needs to be stored, its just like a choose your own adventure type thing, based on the values you pick on the first page will then display certain things on the next page.
Aside from doing things wrong in your opinion, based on what i showed you, I am passing the right page data correct? This should be working?
p.s. angelvision is like going out of business:)
from angel-core.
I really like angel and it would be cool if we could work together to make it so noobs like myself could easily get a page going and learn some laravel at the same time :P
If it was a little bit user friendly to add custom code into the pages it would be a whole lot simpler. But I really do like it :)
And yes your tutorial did help a bunch, i obviously got it extended and working but it just took me having to watch it a number of times:)
from angel-core.
I was merely using an example. You could do it with literally anything, not just contact forms.
I honestly just don't understand your code. For instance:
Route::post('/returnmail', 'PageController@returnmail', array('title'=>'returnmail', 'page'=>'returnmail'));
I have never, in all my years of experience, seen someone passing an array as a 3rd paramater to Route::post
like that. I don't see that anywhere in the Laravel 4.1 documentation, either. I don't know what that is.
And Angel is getting simplified quite a bit for Laravel 5... but, at the end of the day, anything as complex as a CMS does require some proficiency with Laravel. Angel is the simplest CMS I've seen so far, but everything could always be simpler! :)
from angel-core.
Long story short: In order to use the $page
variable, you have to make sure it's being passed to the view correctly. If it's not, you'll get that error that it doesn't exist!
from angel-core.
I was just fooling around trying to set that page variable trying anything I could muster thats all;)
from angel-core.
Ah I see. Cool cool... well I hope that you got all sorted! You can always copy the code from show()
if you need to set up the $page
variable yourself. Just be sure to pass all of the $data
array into your views!
(Because you're not using the show
method like every other page does, you'll have to do anything that it does that is crucial to the views' variables such as loading the $page
model.)
from angel-core.
What file can I find that in?
from angel-core.
This is the PageController, where the show()
method lives that all pages use:
https://github.com/JVMartin/angel/blob/master/src/controllers/PageController.php#L15
from angel-core.
Oh i guess i forgot that i extended the page controller as well..
public function returnmail()
{
//echo "WE WANT THIS TO RETURN THE TEMPLATES BUT ALSO USE OUR DATAZ";
return View::make('pages.returnmail', $this->data);
}
which got me to where i am.
from angel-core.
I think I know what I did wrong now.. I never properly copied over the page controller code i guess lol.
from angel-core.
You shouldn't copy over the PageController code... you've already extended the \Angel\Core\PageController with your local PageController so you're all set, right? I definitely cover all of this in the videos. You don't copy code from the core, you simply extend the classes and overwrite or add any methods you need.
from angel-core.
So i guess I just need to jam in the show code into my returnmail() function?
from angel-core.
As it stands with the function returnmail() and me doing Route::post('/returnmail', 'PageController@returnmail'); i still get page variable errors.
from angel-core.
It's so much simpler than that. In your extended PageController
...
public function post_returnmail()
{
// Do your processing here, then...
return $this->show('returnmail'); // <-- This will *automatically* load the page with an URL of 'returnmail'
}
Have your form post data here, to this method.
from angel-core.
And if you need to return a custom view, then in a separate method:
public function returnmail()
{
return View::make('pages.returnmail', $this->data);
}
from angel-core.
You are rad man! I think I should be able to figure out the rest now:) I am a little unorthodox in my learning,.. Sorry about that..
As for passing an array as a 3rd parameter, is a really bad idea? :P
from angel-core.
It's all good, I'm just glad to help. That show()
method is one of the few methods in the framework where it's really critical to read it carefully and understand completely what it's doing... it loads the requested page from the $url variable and returns either the default page template view or a method by the same name if it finds a method. It will replace dashes with underscores when looking for that method.
All I know is that those functions only accept 2 parameters according to the documentation, so there's no reason to pass a 3rd.
I gotta run for a while, good luck and feel free to hit me up on Skype if you need any more help bro!
from angel-core.
OMG IT WORKS. Thank you so much.
But there is now another issue, my text from the page edited from the WYSIWYG editor is showing on the top left!
http://i.gyazo.com/29ec2e806a9164536339eb1863616d14.png
from angel-core.
Sweet! :) Can you paste me your pages.returnmail
view? It's gotta be the view structure...
from angel-core.
I figured it out :) I was missing the @Stop at the end. We are in business boys!
I'll make sure to highlight that we're using angel when my page goes live whenever it does for sure:)
Thanks again for being patient with the noob!
from angel-core.
Most excellent! :)
No problemo amigo, and thanks - I really appreciate any links back to Angel (though they're not required) and I hope you have fun with it!
from angel-core.
So I found another issue, Following the tutorial you say to customize a page you just change the Controller to
return View::make('pages.home', $this->data);
Now, yesterday you showed me how to load another page using using post, but I want to also customize the page as well and use modules from the admin page however, when I attempt to load the page which i created in the admin section and then its own page2.blade.php with
public function post_returnpage2()
{
return $this->show('page2', $this->data);
}
It ignores the page2.blade.php page completely. Am I doing something wrong?
from angel-core.
My page2.blade.php for edification
@extends('core::template')
@section('title', $page->title)
@section('meta')
{{ $page->meta_html() }}
@stop
@section('css')
@if ($page->css)
<style>
{{ $page->css }}
</style>
@endif
@stop
@section('js')
@if ($page->js)
<script>
{{ $page->js }}
</script>
@endif
@stop
@section('content')
{{ $page->html }}
{{ $page->modules[0]->html}}
test test
test test
@stop
from angel-core.
You're not using the show()
method correctly.
https://github.com/JVMartin/angel/blob/master/src/controllers/PageController.php#L7
I explain the method in detail both earlier in this very thread and also in the YouTube tutorial. It's also only 8 lines of really easy-to-understand code, if you'd prefer to just read it yourself. It's never a good idea to use methods before reading them.
from angel-core.
Shit my bad, i missed one of your updates :) Sorry to be a pain in the ass.
from angel-core.
Thanks again man!
from angel-core.
It's all good man, no problem... so you said it's like a choose-your-own-adventure game? Let me know if you toss it up online, I'd like to check it out!
from angel-core.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angel-core.