/    Sign up×
Community /Pin to ProfileBookmark

PHP frameworks & patterns

hi

I’m looking for some help implementing [URL=”http://www.test-maths.me.uk/img/uml.svg”]this[/URL] in a PHP framework. Ive tried and [URL=”http://codeigniter.com/forums/viewthread/212714/”]failed[/URL] in CodeIgniter. Could someone offer a benchmark, could be CI, Cake or Kohana not fussy. I do like CI however. Files attached.

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@Jeff_MottMar 30.2012 — The class diagram you showed doesn't indicate any kind of web app. What are you expecting a framework to do for you?
Copy linkTweet thisAlerts:
@1cookieauthorMar 30.2012 — The class diagram you showed doesn't indicate any kind of web app. What are you expecting a framework to do for you?[/QUOTE]

hi

And thanks for the response. Indeed, as it stands it's not very useful in terms of a web application. I'm more interested in it from a OOP pattern perspective and in particular implementing this within one of the leading frameworks out there. For this example I'd be happy for the framework to output:

[code=html]
lesson charge: 20. charge type: Hourly rate
lesson charge: 30. charge type: Fixed rate

[/code]


to the browser. Typically using MVC. It would give me (and others no doubt) a benchmark to work with whilst learning PHP frameworks.

I have some CodeIgniter experience but don't have the skills yet to implement the above. It works in native PHP but CI throws exceptions:


[CODE]
Missing argument 1 for Lesson::cost(),

Message: Argument 2 passed to Lesson::cost() must be an instance of CostStrategy, none given

Message: Undefined property: Seminar::$CostStrategy

and

Fatal error: Call to a member function chargeType() on a non-object
[/code]


Whilst I understand the errors, one has to have a deeper understanding of the framework itself to get to the bottom of it.
Copy linkTweet thisAlerts:
@Jeff_MottMar 30.2012 — In the code your posted on the CI forum, you're var_dump-ing $lesson from outside the for loop, which means the variable $lesson probably won't have a value.
Copy linkTweet thisAlerts:
@Jeff_MottMar 30.2012 — That's a very different set of errors than what was posted in the CI forum. You're going to have to show the code you're running.
Copy linkTweet thisAlerts:
@1cookieauthorMar 30.2012 — That's a very different set of errors than what was posted in the CI forum. You're going to have to show the code you're running.[/QUOTE]

hi

OK. Give me one sec, I'll get my most current version from CI...
Copy linkTweet thisAlerts:
@1cookieauthorMar 30.2012 — OK here's the main controller and the view:

[code=php]
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


include ('/var/www/Composition/application/libraries/CostStrategy.php');
include ('/var/www/Composition/application/libraries/Lesson.php');
include ('/var/www/Composition/application/libraries/TimedCostStrategy.php');
include ('/var/www/Composition/application/libraries/FixedCostStrategy.php');
include ('/var/www/Composition/application/libraries/Lecture.php');
include ('/var/www/Composition/application/libraries/Seminar.php');


class Front extends CI_Controller {

public function __construct()
{
parent::__construct();

}

public function index()
{
$data['lessons'] = array();
$data['lessons'][] = new Seminar( 4, new TimedCostStrategy() );
$data['lessons'][] = new Lecture( 4, new FixedCostStrategy() );

$this->load->view('index', $data);

}
}

?>

[/code]


[code=html]
<!DOCTYPE html>
<html>
<head>
<title>Composition with design patterns</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>

<?php
foreach( $lessons as $lesson ){
echo "lesson charge: {$lesson->cost()}.";
echo "charge type: {$lesson->chargeType()}n";
}

/*
* Expecting:
* lesson charge: 20. charge type: Hourly rate
* lesson charge: 30. charge type: Fixed rate
*/


?>
</body>
</html>
[/code]


and the errors, warnings:

[CODE]
A PHP Error was encountered

Severity: Warning

Message: Missing argument 1 for Lesson::cost(), called in /var/www/Composition/application/views/index.php on line 11 and defined

Filename: libraries/Lesson.php

Line Number: 20
A PHP Error was encountered

Severity: 4096

Message: Argument 2 passed to Lesson::cost() must be an instance of CostStrategy, none given, called in /var/www/Composition/application/views/index.php on line 11 and defined

Filename: libraries/Lesson.php

Line Number: 20
lesson charge: 20.
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Seminar::$CostStrategy

Filename: libraries/Lesson.php

Line Number: 30
Fatal error: Call to a member function chargeType() on a non-object in /var/www/Composition/application/libraries/Lesson.php on line 30

[/CODE]


the remaining classes are unchanged.

thanks in advance...
×

Success!

Help @1cookie spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...