Welcome Guest, Not a member yet? Register   Sign In
Is this possible? ( Sub-sub-controller )
#11

[eluser]Q-efx[/eluser]
[quote author="Pascal Kriete" date="1235966349"]I agree with what has been said, but I think a controller for comments might be a little too much separation. Why not make it part of the news controller?

Then just do what feels right:

Create the controller file: /controllers/group/news.php
Add a comment function - parameters (:action) are passed in automatically:

Code:
class News extends Controller {

// .... the usual stuff ...

    function comments($id = FALSE)
    {
        if ($id === FALSE)
        {
            die('no comment id!!');  // or something like that
        }

        // query the db, check for results, and show it or toss an error
    }
}

Hope that helps. Welcome to CodeIgniter.[/quote]

Not really...

The problem will be this: edit a comment would be this url: www.domain.com/groups/news/comments/edit/:id

And for a better "controller" and url flow it would be good to have such a folder path, like: controller/groups/news/comments.php for all "rest" functions ;-)

So it would look like:
[code]
class Comments extends Controller{

function edit ( $id ){
.........
........
}
}

;-)
#12

[eluser]Milos Dakic[/eluser]
[quote author="Q-efx" date="1236032079"][quote author="Pascal Kriete" date="1235966349"]I agree with what has been said, but I think a controller for comments might be a little too much separation. Why not make it part of the news controller?

Then just do what feels right:

Create the controller file: /controllers/group/news.php
Add a comment function - parameters (:action) are passed in automatically:

Code:
class News extends Controller {

// .... the usual stuff ...

    function comments($id = FALSE)
    {
        if ($id === FALSE)
        {
            die('no comment id!!');  // or something like that
        }

        // query the db, check for results, and show it or toss an error
    }
}

Hope that helps. Welcome to CodeIgniter.
[/quote]

Not really...

The problem will be this: edit a comment would be this url: www.domain.com/groups/news/comments/edit/:id

And for a better "controller" and url flow it would be good to have such a folder path, like: controller/groups/news/comments.php for all "rest" functions ;-)

So it would look like:
Code:
class Comments extends Controller{

  function edit ( $id ){
.........
........
}
}
;-)[/quote]

I don't think that will work, but what you can try doing is using what Pascal showed you, and then use a switch method for the edit segment.

Code:
class News extends Controller
{
function comments($do)
{
  switch ($do)
  {
    case 'edit':
    // do something here
    default:
    // do something here
  }
}
}
#13

[eluser]Pascal Kriete[/eluser]
Yes, that will work. If I had to do this I would probably just go with groups/news/edit_comment/:id . However, there are always other options.

Using routing, for example:
Code:
$route['groups/news/comments/edit/(.*)'] = "groups/news/edit_comment/$1";

Of course, to be truly RESTful, you would switch the two:
Code:
$route['groups/news/comment/(.+)/edit'] = "groups/news/edit_comment/$1";

Heck, you could even override the router's _validate_request function and loop through the segment array until the is_dir call fails to build the directory path.

I don't think your url should determine your folder structure - or you'll end up with a lot of very underused folders. In the end it boils down to personal preference. I feel quite comfortable with 20 - 30 controllers per folder with just one level of depth (and if you have a lot more controllers than that I would love to hear what you're building).
#14

[eluser]Q-efx[/eluser]
I want to create my own "social cms" with some unique features. This will not change the world but will have some cool futures ;-)

The realy special things are the "rules" which I want to use. ( If you want to know more: www.u-r-reality.de )

I know that this kind of thing is a "big" project. I would guess it will take 10 years alone. But I hope that later other people will hop in Wink

Well I had to "stop" the project for a while ( Moved to a new location, no internet and so on. But I am now online)

Well so far i drwaed a "model" relationship which will have around 40-60 models ( If you count join tables ) SO yes it will have more controllers then 20-30 ;-)

First I learned php (3) then 5 and after this i found ruby on rails, after a year of: OH and AHS and WOWs. I realized that this thing is tooooooo slow. ( For example if you test a whole project or run migrations you could go and drink a cup of coffee before it even started ;( )

And now I am in the search for a "good" php framework ;-)

Oh, and yes iam thinking about the way: /controller/groups/groups_news_comment.php way Wink
#15

[eluser]Q-efx[/eluser]
Ok I tried to rerout something like this:

$route['groups/news/comment/(.+)/edit'] = "groups/news/edit_comment/$1"; ( dont work i know )

So i tried

$route['groups/news/comment/(.+)/edit'] = "groups/edit_comment/$1";

but i cant get it work, How do i setup if I want to use groups_comments.php in groups folder with the route
www.domain.de/groups/news/comments/:action/:id ( edit, delete and so on ) ?

thx Wink

[edit] Ok forget it got it now , I think to much in ror way ^^




Theme © iAndrew 2016 - Forum software by © MyBB