How to code PHP like a Pro (with a Tech Lead)

preview_player
Показать описание
I show you how to improve your PHP code like the PROs, using Yii2 framework and PHP. I point out a couple of areas that you can look out for and how the MVC structure fits in and also dispel the myth that PHP is 'not for Professionals'.

Credit to nomadtechiemike aka Mike
Saunders.

Remember the 3 rules.
1. Keep it simple, silly (KISS)

2. Less is more
3. Use what you got ... first.

--------Follow Me: ⬇️

Instagram - Yeah, I don't have one.
Рекомендации по теме
Комментарии
Автор

6:23 Principle number 4 - CTRL+S in every app

Lol good video man

maruko
Автор

Nice video, thanks 🙏👍, hoping to see some Laravel tutorials please 🥺

amirjosevelasquezaburdene
Автор

Please make a video comparing different PHP frameworks, how or when to use them?

hmb
Автор

Awesome channel! Subbed! - Thanks Lionel!

salzee
Автор

Hi I really like the way you've created the method for getOnephoto, you can add in upcoming videos working with module I m thinking to change the architecture of my work into modules and submodules, and each module like an entire application that will make the code much cleaner and after watching your video you did inspire me more

Raezon_
Автор

what is the ticking noise in the background ?

PtolemySoter
Автор

Good info Lionel, but when should we use a framework with PHP vs when is it best to just do vanilla php?

EDC.EveryDayCode
Автор

I'm always skeptical of frameworks. It could be gone tomorrow. That becomes a total rewrite for your code.

mucholangs
Автор

very useful, thanks.
p.s. I know nothing about Yii2, but as far as i see, Yii2 has MVC structure and follows REST style, right?

aerahtv
Автор

1000 line functions. Building your own MVC framework. Rejecting web services combining html with php to serve pages.

toddzmijewski
Автор

A better place to put the code to get the photo-url would be a view-helper, instead the model, something like $this->createUrl($photo). This view-helper knows the path of the public photo-folder, the model on the other hand, is just the simple representation of the database-entry.

GGGGGGGGGG
Автор

I.
raw sql complicated if you are beginner, because otherwise i must remember all syntax for active record: find, find_by_id, find_all('name', conditions); ->all(), ->where(), ->attributes() and much much more. if i know mysql base, i can create mysql query simple:

$db->query("SELECT id FROM users WHERE username = ? OR phone = ?", $username, $phone);
$id = $db->result('id');
1. i see raw query
2. i can simple change query
3. i don't need remember AR syntax
4. i can receive only what i want - id, not all object\array
Active record (AR) is not KISS code!

II.

use Smarty\Twig for Html output, never mixing PHP code in template.
<?php foreach ($modelas AS $model) ?>
html <?=$model->name; ?> //work only if php short tag enabled
<?php endforeach ?>

Short and simple way:
{foreach $models AS $model}
html {$model->name}
{/foreach}

III.
All your code could be:
MODEL:
get_random_photo(){
$db->query("SELECT source FROM photo ORDER BY RAND() LIMIT 1");
return $db->result('source');
}

Controller:
$images = array();
for($i =0, $i < 5; $i++)
$images[$i] = get_random_photo();
$smarty->assign('images', $images);

Template:
<div class="container">
{foreach $images AS $image)
<div class="uprofile"><img src="{$image}" class="someclass" alt="cool profile" width="200">
{/foreach}
</div>

webmaster.
Автор

the pro developers are the ones that put their pants two legs at a time, cuz they always want to make everything more difficult lol

wirelesshospital
Автор

I suggest that you can also write function or variable in readable way so can avoid doing comments.

japetsaberon
Автор

sir please make a php mysqli prepare statement registration system add remember me with phpMailer class email send link click after registration and forgot password gmail link send use ui bootstrap 5 error message bootstrap not use oops and pdo

ShahzaibKhan-whhh
Автор

Extracting html logic to model is not very good. Why should model even care how the data/photo will be rendered. I think the best place would be to do it in the view itself.

rakeshthapa
Автор

Can't know how I stopmed onto this. All in all GREAT video 🥇😎. I also watched those rather similar from MStarTutorials and kinda wonder how you guys make these vids. MStar Tutorials also had cool info about similiar things on his vids.

knuttlaarsen
welcome to shbcf.ru