Codeigniter App Tutorial
Lesson 10 of 10 · Codeigniter App Part 10 – Finishing Our App · IT & Software
Codeigniter App Part 10 – Finishing Our App
hey guys alright we're almost done almost there what I want to do now is I want to be able to mark a task complete all right so if we go into a list and
click on a task you can see that it's uncomplete which it means that it's active and I want to be able to click this mock complete and have it completed I want in then it will show down here as
complete all right so once we mark it complete we want to be redirected back to this page to its list so what we need to do is go to let's go to the view let's go to the task view of show the
show view and you can see this mark complete link it goes to the base URL and then the task controller and then the mark complete method and we pass in the task ID all right so we need to
create that so we'll go to the task controller we'll say public function mark new I'm sorry to mark no mark complete and we need to pass in the task ID
and what we're gonna do is we're gonna create a function inside the model called mark new and that will interact with the database so I'm gonna put that in an if statement if this task model
lock new I'm gonna pass in the task ID which comes from the URL all right so if marked new then we want to get the list ID that that task is in because we want to redirect to it so list ID equals this
task model we're gonna say get task list ID get task list ID which of course we need to pass in a task ID and then we're just going to set a message and redirect alright and we're
going to redirect to this slash show slash list ID which we'll get from the model so we have to model functions or methods that we have to create so let's go to our task model and we'll go down
here will create the mokmou okay so what we're gonna do is say this DB set and this is basically an update we're gonna use SEC to update it we're
going to update the is complete value so set we want to set is complete we want to set it to 1 and this DB where we want to say where ID is equal to the task ID that we pass it and then we're going to
do an update so this DV updates and we just want to put in the name of the table which is fascist and then we're just going to return true the next one we want to do is that get
task list ID taxing that task ID okay and we're just gonna do a where statement with a where clause whatever what we want to say this DB where ID is equal to task ID
and now we just want to create a query variable get look I'm gonna put in table name and then we just want to return query row and we want to return just the ID so
this will be role list ID right so that this list ID is coming from if I can just show you it's coming from here in the task table the list ID all right so once we get that we should be able to
redirect to it once we mark it complete so let's just cross our fingers and try this out all right so say test task okay syntax error on task model line 68 oh sorry about that
pick up kids um cannot read eclair get tasklist ID Oh what did I already have it here yeah I did all right so I wrote that I just I already had that method here from earlier so
all right so now we're in the task let's try to mark it complete okay it says the task has been marked new we just need to change that fleet hey let's go to the view to see if
we want tasks show view all right so we want to be able to market new as well you can see we have the link here so it's going to go to tasks slash mark new so basically we'll
just copy this and we just want to do the opposite say mark knew all right so and then in the model looks like we already have mark knew I was I must have did that
I must did that for so let's just copy that and we'll make this one mark complete all right and Mark knew should set it to zero which it set is complete to zero in
my complete sets it to one okay my new my complete and I want to go to the list show view and make sure we have my complete and marked new all right so now let's try to
go to a completed task in market new all right so that moved up here and we'll save mark complete and what didn't all right that one's not marking
complete and I just seen the reason for that is it marked complete we're still passing it to the Mach knew in the model so that has to be my complete alright so that
should work so now if we go into an active task and click mark complete it goes down into the completed tasks and we can do the same thing we can mark these new all right now one thing that
we did kind of skip or miss is that if we delete a list right now it's not going to delete the tasks from that list alright so for instance if we delete the work stuff list well guess
we're still going to have project is do that task is still going to be hanging around so we need to fix that which is pretty easy if we go to our list model you can already see when we delete a
list it's calling this delete tasks of list so we just need to create this in this model if it says this and then of a method that means that the method is in this model alright so I'm going to grab
that and this is gonna be really easy just a couple lines we're gonna say where the list ID equals list ID in tasks then we're going to delete I'm gonna delete
that alright so we'll save this and let's just check out the tasks in PHP myadmin and let's see we have one this project is due task is in the work list alright so let's just delete the work
list work stuff or whatever and we'll click delete list and it's been deleted and now if we go and check out the tasks this project is due should disappear which it does all right so that's just
it's just protecting your your data so you don't have old tasks hanging around that don't even have a parent list so it's very important to keep that in mind with all your projects you always want
to delete anything you can that that's a child of something that you delete all right so the last thing I want to do is just add our latest tasks onto the home page so if we go to our home we want to
go to our home field and under this table I'm gonna post that in which is basically the same kind of thing except it's our tasks and not our list and I'm not sure if we set this in
our controller yet so let's check the home controller and we got the lists so let's uncomment this which is going to give us our tasks in the task model we want to see we want to create this get
users task method so let's copy that and task model and we're just gonna paste this in all right so we're passing a user ID and we're doing that so that we only get the
tasks for our user we don't want other users tasks to show up in our in our admin area all right so we're saying where the list user ID is equal to our user ID all right and if we look in
tasks you can see that there is a there isn't a user oh I'm sorry lists we want to go to lists and you can see that there's a list user ID okay so let's save that and we're also ordering
it by the create date and you can change that if you want so if we reload there's all our tasks we can view each one okay we can delete a task and go home that's you can see that that's gone so that's
it our project is complete and if this was a little longer than I expected I apologize and apologize if I if I went too fast at times copying and pasting but if I just type everything out then
it just gets a little tiring so thanks for watching I hope that you learned a lot and you can now add CodeIgniter to your skill set thanks
The last video of the series. We will create delete methods for our tasks when a list is deleted to promote a smooth flow for CRUD operations
The full source code is at – https://github.com/bradtraversy/mytodo_ci