Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to redirect to another controller... #18

Open
mpfrenette opened this issue Mar 8, 2017 · 2 comments
Open

Trying to redirect to another controller... #18

mpfrenette opened this issue Mar 8, 2017 · 2 comments

Comments

@mpfrenette
Copy link

mpfrenette commented Mar 8, 2017

In order to learn Fat-Free-Framework, I decided to start tweaking Fabulog to add support for Pages (I can share my code when I am done)

Here is what I did:

1 ) Created a new model "Page", new Admin views "page-list.html", "page_edit.html", "page_layout.html", and a new controller "Page". Obviously, these are tweaked copies of your Post versions.

2 ) I added the Page section in the admin menu

3 ) I changed the routing at follows:

             // view list
           $f3->route(array(
              'GET /',
               'GET /page/@page'
              ),'Controller\Post->getList');

        // view single

        // pages have priority: if the slug isn't found in page, we will call Post->getsingle
         $f3->route(array(
             'GET /@slug',
            'GET /p/@slug',
           ), 'Controller\Page->getSingle');


$f3->route(array(
    'GET /post/@id'
   ), 'Controller\Post->getSingle');

4 ) In my page not found handling, I added this:

			if ($this->resource->dry()){
				if (!isset($params['id'])) {

					$postcontroller= new Post();
					$postcontroller->getSingle($f3, $params);

/*
					$f3->route(array(
    			'GET /'. $params['slug'],
       ), 'Controller\Page->getSingle');
*/
				}
				else{
					$f3->error(404, 'Page not found');
				}
			}

But neither methods work...

I instead get a page without the post loaded.

I can simply redirect to /post/@slug

But I was hoping to avoid doing that...

Do you have any ideas?

Here are my thoughts:

1 ) I do not yet fully understand the resource, so it's quite possible that the resource is still trying to work with pages.

2 ) Perhaps it's not possible to route or call a new controller from within a controller without extra initialization?

@mpfrenette
Copy link
Author

I can't seem to make the markup work....

Here is the source code of my controller
page.txt

@codypatnaude
Copy link

codypatnaude commented Mar 14, 2017

The problem may be that you are getting the post but not actually assigning any of the post data to anything that will be rendered in the view.

Take a look at these lines
`

                // copy whole page model, to be able to fetch relations
		// on the fly from within the template, if we need them

		$this->response->data['page']=$this->resource;
		$f3->set('page.title',$this->resource->title.' - '.\Config::instance()->blog_title);`

$f3->set is setting the data that will be rendered in the view.

Once you get the post you need to actually set something in the response that will be read on the front end.

Here's some doc on $f3->set https://fatfreeframework.com/3.6/base

If you want to actually call the posts view as well, you're better off redirecting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants