DevShed continues their series focusing on the CodeIgniter framework with the seventh part - a look at interacting with the database to update, delete and insert rows from your application.
You've seen some of the things you can accomplish with the Code Igniter PHP framework in earlier parts of this series. In this seventh part of the series, you will learn, through copious examples, how to perform insertions, updates and deletions on a selected MySQL table by using Code Igniter's database class. You'll see that these tasks are very intuitive and easy to grasp, thanks to Code Igniter's friendly learning curve.
They show how to make conditional select statements (with where clauses) and do both inserts of new information and updates to current information, all with the built-in model functionality the framework provides.
DevShed has posted the next part of their series focusing on the CodeIgniter framework. This new tutorial looks at the Active Record class that sits at the heart of the framework.
Welcome to the sixth installment of the series entitled "Introducing the Code Igniter PHP Framework." By using a hands-on approach, this series of articles walks you through the main features that come packaged with this friendly yet powerful development software that lets you quickly build robust PHP applications.
They show a simple example of how to pull information out of your database, how to get a little more complex with conditional select statements and how to use a where to narrow down your results.
On the symfony blog today, there's a new post that looks at creating a conditional validator in the context of a classic login form for the framework.
Jon works on a symfony 1.1 project with a classic login form. The form is composed of two fields: a username and a password. The validation rules are quite straightforward: he wants each field to be required and he wants to check the correctness of the password.
They show how to set up a normal login widget and how to apply a sfValidatorCallback in the configure() method to check the values in the form. This method checks the username and password values and tosses an error with sfValidatorError if a problem is found.
Padraic Brady has written up a post on how he implemented conditional fetching (GET) as a part of the Zend_Feed component of the Zend Framework.
You see, by default, Zend_Feed is stupid. It will blindly drag in whatever RSS you point it at, parse it, present an accessible API (which is largely an abstract API across PHP DOM), and then merrily sit back while you are driven demented. There is a problem in blindly fetching RSS and parsing it - RSS feeds from a huge number of online sources only change rarely. The rest of the time the feed is unchanged.
The key is in the "Last-Modified" header data of the remote file (and ETag). He shows how to use this knowledge in a simple example - pulling data with a ZFBlog_Aggregate class and dumping the contents into a database table. This code checks the return status for a 304 ("Not modified") and closes out the connection if so. Otherwise it grabs the content and updates the database with the most recent fetch times to compare to the "Last-Modified".
The Zend Developer Zone has posted a new article today with three tips to help you make your code a little easier to understand (both by other coders and yourself down the road).
Producing code that clearly conveys a developer's intent is key to any well written application. That not only applies to PHP, but every programming language. Developers who emphasize the creation of legible code tend to create applications which are easier to both maintain and expand upon.
His tips include suggestions about keeping conditional logic clean, using "less PHP and more HTML" and to make the best possible use that you can out of sprintf "and friends".
The PHPFreaks.com website gets back to basics with a new tutorial they've posted - a look at looping in PHP.
Looping is simply a way for you to reduce the amount of code and/or content you have to write out. The idea is that you have something you have to do, or some content you have to show, and instead of just "writing it all out," you find a pattern to it - a common denominator - and let PHP execute the code or generate the content piece by piece using that pattern, based on a condition.
Their example solves the problem of finding taking a range of numbers and seeing how many of them can be evenly divided by another number.
On the Debuggable blog, Tim Koschutzkishows how to use grouping in your SQL statements with the find() method calls inside of a Model for an app.
We have to thank Mark Story and wluigi for working on group by conditions for Cake's Model::find() method. Up until now, you would have to add your GROUP BY stuff to string'ed conditions in order to support a group by statement, which could be very ugly.
He has some code included that compares the two methods - the newer of the two applying the 'group' option as a regular condition to the query object.
This functionality is currently only in the the Release Candidate 1 but will be included in the next major release.
The PHPBuilder.com site has a quick reminder about a handy little bit of functionality PHP has to make evaluations quicker - the ternary operator.
This allows you to check for the existence of a variable (or check that the variable has a valid value) and assign a value accordingly. This is very useful when you are dealing with $_GET, $_POST, $_SESSION etc. variables, because you don't know whether the incoming variable will exist, and if it doesn't you might want to assign a default value.
An example is included and explained - evaluating an index in the _GET superglobal to see if it exists. It returns either the value itself or a false.
DevShed has posted the latest part of their introduction to PHP series, this time focusing on one of the more useful features of the language - conditionals and loops.
We discussed statements briefly in our last article and even got a sneak peek of an IF-statement. Sure I mean, the image was blurry, and the moment it saw us it ran off into the forest. But we saw it. Honest. So in this article, we're going to take a much closer look at PHP statements and even start learning about loops.
They cover if statements (as mentioned) as well as introduce you to its companions, else and else if. The finish off the article with a brief look at one of the simpler loops, the for loop.
Stefan Mischook has another video tutorial posted today for the PHP beginners out there, this time covering the use of conditionals.
The following video teaches the basics of conditional statements in PHP; specifically the 'if' statement.
The video gives a very basic overview of what the 'if' statement is good for, code examples of how to use it including else/elseif and nested if statements.