How to retrieve object from angular posting method to my php script

55 views
Skip to first unread message

beastar 457

unread,
Jul 7, 2015, 10:00:58 AM7/7/15
to ang...@googlegroups.com
my method that is in my service is like this 

 tutorial.createtutorial = function(tutorial){
    var defer = $q.defer();

    $http.post($rootScope.endPoint + '/api/v1/follower', tutorial)
    .success(function(res){
        defer.resolve(res);
    })
    .error(function(err, status){
        defer.reject(err);
    })

    return defer.promise;
  }


and how can i get the passed object into php script so that i can insert it into database

Armando Couto - Gmail

unread,
Jul 7, 2015, 10:11:10 AM7/7/15
to ang...@googlegroups.com
Take a look at this PHP code, using PHP Slim.

CONTROLLER
$app->post("/courses", function () use ($app, $dao, $improvementDao, $postGraduationDao) {

    $json = $app->request->getBody();
    $data = json_decode($json, true);

    $course = new Course();
    $course->setName($data);
    $course->setIntroduction($data);
    $course->setObjetive($data);
    $course->setTargetPublicForm($data);
    $course->setWorkload($data);
    $course->setEarlyForecastForm($data);
    $course->setPeriodicity($data);
    $course->setSchedule($data);
    $course->setCoordination($data);
    $course->setInstructor($data);
    $course->setInformationAddForm($data);
    $course->setStatus($data);
    $course->setActive($data);
    $course->setFaculty($data);
    $course->setSeal($data);
    $course->setCreatedBy($data);
    $idCourse = $dao->insert($app, $course);

    responseJson($app, 201, "");
});

MODEL
<?php

class Course
{
    public $id;
    public $name;
    public $introduction;
    public $objetive;
    public $targetPublic;
    public $workload;
    public $earlyForecast;
    public $periodicity;
    public $schedule;
    public $coordination;
    public $instructor;
    public $informationAdd;
    public $status;
    public $active;
    public $createdBy;
    public $changed;
    public $changedBy;
    public $type;
    public $dates;
    public $faculty;
    public $seal;

    public function setId($course)
    {
        $this->id = $course["id"];
    }

    public function setName($course)
    {
        $this->name = $course["name"];
    }

    public function setIntroduction($course)
    {
        if (isset($course["introduction"])) {
            $this->introduction = $course["introduction"];
        }
    }

    public function setObjetive($course)
    {
        if (isset($course["objetive"])) {
            $this->objetive = $course["objetive"];
        }
    }

    public function setTargetPublicBD($course)
    {
        $this->targetPublic = $course["target_public"];
    }

    public function setTargetPublicForm($course)
    {
        if (isset($course["targetPublic"])) {
            $this->targetPublic = $course["targetPublic"];
        }
    }

    public function setWorkload($course)
    {
        if (isset($course["workload"])) {
            $this->workload = $course["workload"];
        }
    }

    public function setEarlyForecastBD($course)
    {
        $this->earlyForecast = $course["early_forecast"];
    }

    public function setEarlyForecastForm($course)
    {
        if (isset($course["earlyForecast"])) {
            $this->earlyForecast = $course["earlyForecast"];
        }
    }

    public function setPeriodicity($course)
    {
        if (isset($course["periodicity"])) {
            $this->periodicity = $course["periodicity"];
        }
    }

    public function setSchedule($course)
    {
        if (isset($course["schedule"])) {
            $this->schedule = $course["schedule"];
        }
    }

    public function setCoordination($course)
    {
        if (isset($course["coordination"])) {
            $this->coordination = $course["coordination"];
        }
    }

    public function setInstructor($course)
    {
        if (isset($course["instructor"])) {
            $this->instructor = $course["instructor"];
        }
    }

    public function setInformationAddBD($course)
    {
        $this->informationAdd = $course["information_add"];
    }

    public function setInformationAddForm($course)
    {
        if (isset($course["informationAdd"])) {
            $this->informationAdd = $course["informationAdd"];
        }
    }

    public function setStatus($course)
    {
        if (isset($course["status"])) {
            $this->status = $course["status"];
        }
    }

    public function setActive($course)
    {
        $this->active = $course["active"];
    }

    public function setCreatedBy($course)
    {
        $this->createdBy = $course["createdBy"];
    }

    public function setChanged()
    {
        $this->changed = (new \DateTime())->format('Y-m-d H:i:s');
    }

    public function setChangedBy($course)
    {
        $this->changedBy = $course["changeBy"];
    }

    public function setType($type)
    {
        $this->type = $type;
    }

    public function setDates($improvement)
    {
        $this->dates = $improvement[0]["dates"];
    }

    public function setFaculty($postGraduation)
    {
        if (isset($postGraduation["faculty"])) {
            $this->faculty = $postGraduation["faculty"];
        }
    }

    public function setSeal($postGraduation)
    {
        if (isset($postGraduation["seal"])) {
            $this->seal = $postGraduation["seal"];
        }
    }
}

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.



--
Att
Armando Couto 
CSM - LKU

beastar 457

unread,
Jul 7, 2015, 10:23:54 AM7/7/15
to ang...@googlegroups.com
$json = $app->request->getBody();
    $data = json_decode($json, true);

does the above get content posted by angular?

coutoa...@gmail.com

unread,
Jul 7, 2015, 11:13:51 AM7/7/15
to ang...@googlegroups.com
json is coming in the body of the request

Enviado do meu iPhone
--

beastar 457

unread,
Jul 7, 2015, 11:26:31 AM7/7/15
to ang...@googlegroups.com
that is nice it worket in my case i found out that is hould do like this :

$data = json_decode(file_get_contents("php://input"));
return Response::json($data);

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/_1cYcKIUK9k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.

beastar 457

unread,
Jul 8, 2015, 3:52:54 AM7/8/15
to ang...@googlegroups.com
hello i have controller that it has to give me an image and i am calling it like this
 <div class="col-xs-3" ng-controller="Parse">
                        <img src="{user}" class=" img-circle Circle__image" alt="Image" style="width:80px; height:80px;">  
    </div>
the image is comming but when i go to console it saying that  localhost:8000/image4545 mot found? what is the problem here?

Armando Couto - Gmail

unread,
Jul 8, 2015, 8:16:33 AM7/8/15
to ang...@googlegroups.com

beastar 457

unread,
Jul 8, 2015, 8:24:33 AM7/8/15
to ang...@googlegroups.com
big thanks i really appreciate your help and i wish that you can be in my team on my amazing project that i am building thanks again. 

beastar 457

unread,
Jul 8, 2015, 9:29:53 AM7/8/15
to ang...@googlegroups.com
sir, how can i put default image to before angular finish to load image from server to avoid empty emg that comes when image is not fully loaded?
Reply all
Reply to author
Forward
0 new messages