Code Monkey home page Code Monkey logo

apprentice.dev's People

Contributors

miketayc avatar samtay avatar

Watchers

 avatar  avatar  avatar

Forkers

lapty

apprentice.dev's Issues

Improve Accessing Data

As we discussed, there are many ways to do this. If you think it will take too much rework to remove the standard class usages, then at least wrap each access with a ternary operator check. For instance,

echo $lesson->name ▶️ echo (!empty($lesson->name)) ? $lesson->name : ''

If you instead refactor to pass back PDO::FETCH_ASSOC and wrap data in your Core_Model_Object, then your checks are already performed in that class:

if ($lesson instanceof Core_Model_Object) {
    // Won't throw errors even if 'anything' key doesn't exist in $lesson->_data
    echo $lesson->getAnything();
}

Goddamnit Mike

Change the git username on my laptop. It looks like I made a shit-ton of commits to this repo.

Decouple user model into separate classes

As discussed, methods that don't have to do with any specific model should get moved into a Core_Model_Abstract class, which extends Core_Model_Object. For example,

App_Model_User::getCount() ▶️ Core_Model_Abstract::getCount()

Similarly, methods that have nothing to do with user but only other tables, should be moved into their own model class. For example,

App_Model_User::getAllTagsFromTagTable() ▶️ App_Model_Tag::getAll()

App_Model_User::getAllLessonNames() ▶️ App_Model_Lesson::getAllNames()

Mimic Magento

These come way after the other issues in terms of priority.

  • First of all, you don't really have modules right now. You have a lib, containing framework stuff, but your app is one giant incubate module. Really, you could have user module, lesson module, etc. Not the end of the world, but it would make more sense to have helpers, models, etc., specific to each module.
  • Each model instance represents a row in the database, requiring methods like
    $model->load($id), $model->save(), which either updates or inserts depending on id existing on model instance. Then creating a lesson looks like this:
$lesson = Bootstrap::getModel('incubate/lesson');
foreach(array('name', 'date_due', 'description') as $field) {
    $lesson->setData($field, $_POST[$field]);
}
$lesson->save();

and updating looks like

$lesson = Bootstrap::getModel('incubate/lesson')->load($_POST['id']);
$lesson->setName($_POST['name'])->save();

Of course, in doing this, you'd make use of the abstract save method, but you'd also need to do some validation to make sure that you don't save blank lessons. Probably a protected array of $_requiredFields that must exist on _data before the object is saved via parent method.

  • Any methods not specific to a model row get moved into a model resource or helper class. So you can call
$userCollection = Bootstrap::getHelper('incubate/user')->getAllUsers();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.