PHP & MySQL novice to ninja - what's next?

Hey, Tom.

This question is unrelated to URL Rewriting but totally about your book (couldn’t find where else to post it). Feel free to move it.

I’d be really grateful if you would post a brief comment on the following.

Let’s say I have worked through your book beginning to end (very nearly there) and have ended up with the IJDB site, most of it beautifully set up in NINJA with a few files in IJDB. All works well. :sunny: My UI design skills are not the best so I want to integrate what I’ve ended up with from your book with a UI helper.

I’ve had a look at Bootstrap and WordPress. Bootstrap seems to be just CSS based so I guess there’d be no problem there. WordPress, however, seems to use a physical file structure that bears no resemblance to what I’ve got with IJDB. Adding a new page for example involves something totally different to adding methods to IjdbRoutes… I understand the difference between Bootstrap and WordPress (never used either, yet, but researched a bit). Would any CMS work with your completed IJDB site or would we have to develop further (assuming a future of adding more sections and features to the IJDB site) the small CMS you have started. How would we use that to say, add a page to teh site?

I’m not particularly keen on WordPress anyway but I’d just like your take / guidance on integrating your IJDB completed site with these two technologies.

Or, indeed, if you have a better idea altogether?

I know this is a topic you could talk about all week, I’m only hoping for a brief response to point me in the right direction and save me wasting time going down roads that will never work.

Cheers, Tom.
Mike

I think the book shows you how to build your own simple CMS, whereas WP is a pre-built CMS. So it’s really two different things.
For styling, WP does have a number of pre-made themes for it, but you can’t really apply those themes to your own custom, hand-built CMS.
WP can be used by someone who does not know how to, or just doesn’t have the time to “roll their own” CMS. Though some do build their own WP themes or add-ons, so you you could maybe use your new found skills to do that, it that is what you want to do.
Bootstrap is a different subject altogether, it’s for managing page layouts. You could use it to style your own work. But it’s no short-cut to learning CSS. You need to know css to use Bootstrap, and if you know css, you know you don’t necessarily need Bootstrap to make a responsive layout.
Personally I’m not a fan of either WP or Bootstrap. But both do have their pros and cons and do suit some people/sites/production pipelines, and you should hear some varying opinions on them here for your consideration.

SamA74,

Thank you very much for your response. I guessed as much. And, in a way, I’m glad you’ve said that. There seems to be so many disadvantages to each. I’ve just come to PHP from ASP.NET where, again, the framework does a LOT for you. I wanted to get back to HTML5, CSS and, perhaps, a little JS. A purer, cleaner approach. You’ve convinced me to “roll my own” as you say.

Perhaps, if anyone is interested (I certainly am), this thread could be used to propose some ideas about precisely that: fully respecting the outstanding purity of the framework Tom has built, how can we go about extending the CMS?

  • Add a new page

  • Create a two-level navigation (individual pages within broader “areas”)

  • Handling email.

  • Etc.

I do this kind of thing daily, as I suppose we all do but… how to do it without “tarnishing” (for want of a better word) the pure framework we are beginning with. Let’s keep the Ninja / Ijdb separation and the method of re-using Ninja very clear. You know… what aspects of handling email are generic? what project-specific? Tom has consistently overcome the problem of not knowing precisely what arguments a particular class will need by sending arrays. Could we use something similar the build a generic navigation scheme which might be a single page, one-level, two-level, etc?

Anyone interested?

You would have to develop further. You could take the classes and use them in WordPress (though the only potentially useful one would be DatabaseTable). When you have finished the book, you end up with a basic framework. This is more like Symfony or Laravel. Bare bones sets of classes that you can use to develop any site you like. Wordpress is a fully functional website that you can build on top of .

In short: A CMS can be used without writing any code. A framework provides building blocks that you can develop onto

I wouldn’t recommend wordpress to anyone. It’s a bane on the PHP community and is the primary inspiration and source of thousands of awful developers that give professionals a bad name.

There’s not a lot of work to create a CMS. You’ll need the tables category and post and a controller similar to the Joke controller for both: You’ll need a page for adding categories and a page for adding posts. For adding posts, you’ll probably want to use something like TinyMCE for WYSIWYG editing.

When adding a post you’d select the category from a drop down, like we do with jokes in the book.

This is a bit more complicated, but there are two general methods. parent/child and nested set. Nested sets are harder to understand and implement ( http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/ ) so you’re probably better off with a simple parent child. Each category in the table has a parentId column and the table might look like this:

id    name           parentId
1     Electronics    0
2     Furniture      0
3     Computers      1
4     TVs            1
5     Chairs         2
6     Sofas          2

Then, to get a list of top level categories, you can use SELECT * FROM category WHERE parentId = 0 or, using the DatabaseTable class: $categoryTable->find('parentId', 0)

Then to find all categories inside electronics you can use SELECT * FROM category WHERE parentId = 1 which will give you Computers and TVs.

Building on the book, you can create an entity class that looks like this:


class Category {
	public $id;
	public $name;
	public $parentId;

	private $categoriesTable;

	public function __construct(\Ninja\DatabaseTable $categoriesTable) {
		$this->categoriesTable = $categoriesTable;
	}

	public function getChildren() {
		return $this->catgoryTable->find('parentId', $this->id);
	}
}

Then create a template to display all the categories:


<ul>
<?php foreach ($categories as $category): ?>
	<li>
	<?= $category->name; ?>
	<?php
		$subcategories = $category->getChildren();
		if ($subcategories) {
			$this->loadTemplate('category.html.php', ['categories' => $subcategories]);
		}
	?>
	</li>
<?php endforeach; ?>
</ul>

This is a bit more advanced than anything in the book because it loads the same template recursively. If the category being looped over has subcategories, it loads the template again.

Hey, Tom.

Thank you so much for your reply, especially the detail you’ve gone into to help me. Very much appreciated.

Your comments on WordPress made me smile:
“I wouldn’t recommend wordpress to anyone. It’s a bane on the PHP community and is the primary inspiration and source of thousands of awful developers that give professionals a bad name.”

Don’t sit on the fence, now. :slight_smile: I’m glad you’ve said that. Something inside me was wanting a pro to say “Leave it alone”.

Right, if anyone else IS interested in posting some code ideas for building on top of Tom’s work, for myself I’m going to a) finish the book, and b) take what Tom has given here and work the navigation through. I’ll post results and hope to hear from others with ideas.

Again, Tom, thanks for the book and thanks for the care you’ve shown in your response.

Mike

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.