• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Practical CodeIgniter 3 - A new book coming soon

#31
(01-28-2016, 10:17 PM)webcodeguy Wrote: Thank you, reading the sample now. Looking forward eagerly to the complete book Smile

Thanks! I have the next chapter written, and it's waiting for review by Mat. The chapter after that is 1/3 finished, so we're getting there! Smile
Practical CodeIgniter 3  • CodeIgniter 4 Foundations - Coming Soon • Vulcan - CLI Tools for CI4
Reply

#32
The latest chapter is out.

This chapter covers Multiple Applications, the settings and tools you have at your disposal to make the pieces work together, and we look at how you would modify everything to cover 4 different use cases.
Practical CodeIgniter 3  • CodeIgniter 4 Foundations - Coming Soon • Vulcan - CLI Tools for CI4
Reply

#33
Hello guys,
I am new to CodeIgniter and I ask your help.
I bought the book and I'm in doubt about how to use the "A Simple Theme System." Someone could send me a working example ?!  I'm a little lost.. Confused
It will help me a lot.

Thank you!
Reply

#34
The simplest solution is to put the code in that chapter into your MY_Controller file. The My_Controller example file that you should have received with the book has the functions already in there. Then, all of your controllers would extend from that. At this point, all of the functions are available to your controllers. Then, the $this->render() method would display the current view based on your controller and message name. We'll walk through a quick example assuming a user profile page.

First, create your main "layout" file. This is the template that is used for all of the pages that your content gets inserted into. Make sure the echo out a view_content variable.

Code:
<!doctype html>
<html>
<head>
    <title>Some Great Site</title>
    <link rel="stylesheet" href="/assets/css/app.css">
</head>
<body>
    <!-- Header stuff goes here -->

    <div class="container">
        <?= $view_content ?>
    </div>

    <!-- Footer stuff goes here -->
</body>
</html>

Then, in your controller, you might do something as simple as:

Code:
class Users extends MY_Controller {
    public function index() {
        $data = [
            'user' => $this->auth->current_user();
        ];

        $this->render($data);
    }
}

This will look for a view file at application/views/users/index.php. You would fill that view file with any content that you needed to, and it would be inserted into the layout file at the place where the $view_content is output.

There's more details to it, of course, but is that enough for it all to make sense? Sounds like I need to clarify that part of the book a little more with an example or two.
Practical CodeIgniter 3  • CodeIgniter 4 Foundations - Coming Soon • Vulcan - CLI Tools for CI4
Reply

#35
Nice book.

Can you put an example how to use a crud with many to many table? Smile
Reply

#36
(02-19-2016, 07:50 AM)Paradinight Wrote: Can you put an example how to use a crud with many to many table? Smile

That sounds like a good exercise for the reader. Smile

Actually, if what you're looking for is a mini-ORM, that you should take a look at Avenirer's MY_Model. While I haven't used it before, it incorporates most everything that the MY_Model I've used for several years does, as well as some extra goodies like built-in pagination, and relationships.
Practical CodeIgniter 3  • CodeIgniter 4 Foundations - Coming Soon • Vulcan - CLI Tools for CI4
Reply

#37
(02-19-2016, 10:05 AM)kilishan Wrote: Actually, if what you're looking for is a mini-ORM, that you should take a look at Avenirer's MY_Model

When you say your My_Model, do you mean CIDbModel.php in your Sprint package?
Reply

#38
(02-19-2016, 01:24 PM)tflight Wrote: When you say your My_Model, do you mean CIDbModel.php in your Sprint package?

That's the base model class that Sprint uses, and does the same thing as a more "traditional" MY_Model class extension that CodeIgniter provides. Avenirer's provides features that Sprint's doesn't, like the ability to handle relationships, as the OP was asking about.
Practical CodeIgniter 3  • CodeIgniter 4 Foundations - Coming Soon • Vulcan - CLI Tools for CI4
Reply

#39
@kilishan
The model class have two bugs.

find($id) and find_all() need a small fix

PHP Code:
public function find_all()
 
   {
 
       $query $this->db->get($this->table_name);

 
       $rows $this->temp_return_type == 'array' ?
 
                   $query->result_array() :
 
                   $query->result($this->temp_return_type);

 
       $this->temp_return_type $this->return_type;

 
       return $rows;
 
   


PHP Code:
public function find($id)
 
   {
 
       $query $this->db->where($this->primary_key$id)
 
                     ->get($this->table_name);

 
       $row $this->temp_return_type == 'array' ?
 
                   $query->row_array() :
 
                   $query->row(0$this->temp_return_type);

 
       $this->temp_return_type $this->return_type;

 
       return $row;
 
   

I added "db". Without the "db" the code do not return rows Smile
Reply

#40
Oops - I forget to mention that the book was completely wrapped up a week or two ago. So, if you've been waiting until it was finished to grab a copy, now's the time!

For those that were patient with me for the last 7 or 8 months, I apologize, but much of the time that I should have been writing was spent building out CodeIgniter 4. I hope you don't mind! Smile
Practical CodeIgniter 3  • CodeIgniter 4 Foundations - Coming Soon • Vulcan - CLI Tools for CI4
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.