Wiseguysonly has been my blog for over 10 years. It’s dated, but still gets lot’s of visitors.
So, I’m leaving it where it is, but from now on I am moving to other pastures, so you can find my latest thoughts here:
Wiseguysonly has been my blog for over 10 years. It’s dated, but still gets lot’s of visitors.
So, I’m leaving it where it is, but from now on I am moving to other pastures, so you can find my latest thoughts here:
One of the bigger issues of Rich Text Editors in Content Management Systems is that even in the hands of the best users they can generate all manner of spurious content.
Here is a quick way ,using regular expressions, to remove any of these unnecessary HTML elements from your output content. This example removes paragraphs that contain only line breaks, non-breaking spaces or white-space.
This is specifically for <p> tags, but I’m sure you can figure out how to adapt it to your needs.
echo preg_replace("/<p[^>]*>[\s| ]*<\/p>/", '', $your_content);
Here’s a quick tip in case you are losing sessions on your CakePHP with no apparent reason. Check any components that you are using for whitespace (usually at the end of the file).
I came across this recently whilst helping a client with their existing CakePHP site, when logged in one particular page that called a component was killing $this->Session->read(‘Auth’).
As a bonus, here is a lovely CakePHP shell that you can use to find whitespace.
Mutt is a fantastic terminal based email client that has all of the capabilities of its GUI based equivalents. One thing I always found annoying was being unable to read emails that have been sent as HTML only (ugh). Well, here is a nice fix that let’s you use a terminal based web browser to view the emails as soon as you load them, in mutt, with as much formatting as possible maintained.
text/html; lynx %s; nametemplate=%s.html
text/html; lynx -dump %s; nametemplate=%s.html; copiousoutputauto_view text/htmlNow you can start enjoying your HTML email from within Mutt.
I covered a very simple way to implement alternating table row colours with PHP in another post (6 years ago!). Here is a way to achieve the same client side using jquery. It could easily be used for any set of elements (e.g. li)
$('.table').each(function (i, e) {
if (i % 2 == 0) {
$(this).addClass('highlight')
}
});
All you need then is a .highlight rule in your css to do the styling.
A quick gotcha here that leverages CakePHP’s inbuilt utilities to hash data before you commit it to the database.
The beauty of this method is that you can still run all your validation checks and then hash the data between validation and saving. Why is that important? Consider you have a rule that says a password should be no more than 15 characters. When you hash it, it would break the rule and your record would never save.
All you have to do is hash your fields in the beforeSave function of your model like this example from a User Model:
public function beforeSave() {
App::uses('Utitlity','Security');
if(!empty($this->data['User']['password'])) {
$this->data['User']['password'] = Security::hash($this->data['User']['password']);
}
return true;
}
One import aspect of this is to always return true. If you don’t your record will NEVER save.
There’s no point in me trying to sell mongoDB to you, just go over to the mongoDB site and read up on its excellence.
This is how I got mongoDB working on Debian Squeeze. It should work for other Deb based flavours – I’m thinking Ubuntu. I also have a PHP5x setup so you may need to adapt if you are running earlier versions. I’m also assuming you have git installed to fetch the drivers.
All you have to do follows:
First install the necessary mongo stuff (you need php5-dev also as we need the phpize functionality):
sudo apt-get install mongodb mongo-clients php5-dev
Now fetch the official mongoDB php driver from github:
git clone https://github.com/mongodb/mongo-php-driver.git
Change into the driver directory and run the following commands:
cd mongo-php-driver
phpize
./configure
sudo make install
Copy the driver to php extension dir. To find your extension dir run:
php -i | grep extension_dir
Armed with the location of your extension dir copy the file:
sudo cp modules/mongo.so /path/to/php/extension_dir/
Now create a file to load the driver into php at start up:
sudo vi /etc/php5/conf.d/mongo.ini
with the line:
extension=mongo.so
Now restart apache:
sudo /etc/init.d/apache2 restart
Then start an instance of the mongo server and PHP should be mongo friendly.
If you want to test this go grab a copy of the excellent phpMoAdmin and drop the file anywhere you load it through a browser. It should connect off the bat to mongoDB and you can start creating collections and objects in less time than it takes you to type “CREATE TABLE …”.
Enjoy.
It sells itself:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | Feature: Tutor forums As a Tutor I want to be able to use the forums In order to communicate with other tutors Scenario: View forums Given that I am logged in as a Tutor And I click on "Tutor Forums" Then I should see a paginated list of "Tutor Forums" Scenario: Create forum Given that I am logged in as a Tutor And I am on the page "Tutor Forums" And I click on the link Create forum And I enter a Forum title And I click "create forum" Then I should be able to create a new forum. Scenario: Edit forum Given that I am logged in as a Tutor And I am viewing a forum that I created And The forum was created within the past 15 minutes Then I should be able to edit the forum Scenario: View threads Given that I am logged in as a Tutor And I am on the page "Tutor Forums" And I click on the title of a Forum I should see a paginated list of threads for that forum. Scenario: Read thread Given that I am logged in as a Tutor And I am viewing a list of forum threads And I click the title of a thread Then I should see a list of message for that thread. Scenario: Reply to thread Given that I am logged in as a Tutor And I am viewing a thread And I click "post reply" And I enter a reply And I click "post reply" button Then I should be abñle to reply to a thread Scenario: Edit reply Given that I am logged in as a Tutor And I am viewing replies to a thread And a reply was posted by me And the reply was posted within the last 15 minutes Then I should be able to edit the reply. |
It’s so easy you and your clients can learn it in minutes, and it saves everyone time and clarifies expectations.
PHP users should check out Behat.
The new website for my CakePHP development company, Zumo Internet is now live.
I’ve been building with PHP for 10 years, but over the past 2 years all of my projects have been built using CakePHP. I’ve never looked back as far as stability and speed of development is concerned.
So if you are looking for a CakePHP developer, please visit and maybe hire me.
I enjoy CakePHP’s structure and methods so much that I have started using it for my non-database driven projects and for prototyping big projects.
However, when no database is present CakePHP throws a warning that it can’t connect to the database. The solution is to create a dummy database connection to convince CakePHP that all is ok. And, it’s as simple as this:
Create a new folder app/models/datasources/dbo
Create a new file at app/models/datasources/dbo/dbo_dummy_db.php and add the following:
1 2 3 4 5 6 7 | <?php class DboDummyDb extends DboSource { function connect() { $this->connected = true; return $this->connected; } } |
In your app/config/database.php find the default connection array – a line that starts $default = array
and replace the line for the driver from
'driver' => 'mysql',
to
'driver' => 'dummy_db',
And that’s all there is to using CakePHP without a database.